I have a component that display attributes of an object on form. I used getter/setter method of typescript to detect the changes of 2-ways data binding on form using model. Here's my code:
export class AlterInfoComponent implements OnInit {
_alterInfos: any = {};
@Output() alterInfosChanges = new EventEmitter();
@Input() get alterInfos () {
return this._alterInfos;
};
set alterInfos(val) {
this._alterInfos = val;
this.alterInfosChanges.emit(val);
console.log('Alter Infos Changed: ', this._alterInfos);
}
}
And my HTML template code:
<div>
<input type="text" [(ngModel)] = "alterInfos.id">
<input type="text" [(ngModel)] = "alterInfos.name">
</div>
When I change the input on html form, the console log doesn't return any message. Any suggest?