I've got an Angular 2 Controller which looks like this:
@Component({
selector: 'my-component',
template: '<div>The value is: {{ value }}</div>',
})
class MyComponent implements OnInit {
@Input()
value: string;
@Output
valueChange = new EventEmitter<number>();
ngOnInit() {
this.valueChange.subscribe(value => {
console.log('new value:', value); // <-- does not get triggered
});
}
}
But when the value of value
changes from a template binding:
<my-component [value]="someValue" /> <!-- valueChange not triggered! -->
The valueChange
event isn't triggered so, even though the template correctly updates and shows the new value, the component doesn't know it's been changed.
How can I detect when input attributes on my controller are changed?