using the ng change in angular 2 using ng model variable
You could use the ngModelChange
event:
[(ngModel)]="variable" (ngModelChange)="doSomething($event)"
Edit
According to your comment, I think that you should use form control with a custom validator.
Here is a sample:
@Component({
(...)
template: `
<input [(ngModel)]="variable" [ngFormControl]="ctrl"/>
`
})
export class SomeComponent {
constructor() {
this.ctrl = new Control('', (control) => {
// validate the value
});
this.ctrl.valueChanges.subscribe((value) => {
// called when the value is updated
});
}
}
See this article for more details:
- http://restlet.com/blog/2016/02/11/implementing-angular2-forms-beyond-basics-part-1/
component have two-way binding
()
for output[]
for input
that means you can use ==>[value]="variable"
<== for showing data on html
and ==>(input)="setVariable($event)"
<== to update your var in ts/js.
event.target.value
FYI==>https://angular.io/docs/ts/latest/guide/user-input.html