Is there a way for my angular2 component to accept a function as a parameter?
Uncaught Error: Template parse errors: Can't bind to 'click' since it isn't a known property of 'input'. (" minlength="{{minlength}}"
[ERROR ->]click="{{click}}"
"): ng:///AppModule/InputTextComponent.html@12:2
ComponentInput.ts
import { Component, OnInit, ViewEncapsulation, Input, Output, EventEmitter } from '@angular/core';
import { NgModel } from '@angular/forms';
@Component({
selector: 'app-input-text',
templateUrl: './input-text.component.html',
styleUrls: ['./input-text.component.css'],
encapsulation: ViewEncapsulation.None
})
export class InputTextComponent implements OnInit {
@Input() id: string;
@Input() name: string;
@Output() click = new EventEmitter();
constructor() { }
ngOnInit() {
}
}
Template Input Component:
<input
type="text"
id="{{id}}"
name="{{name}}"
click="{{click}}"
>
Component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
clique() {
console.log('Clicando...')
}
}
Componente.html
<app-input-text
id="2"
name="nome"
(click)="clique(event)"
ngDefaultControl>
</app-input-text>