Reputation: 25
I want to exec a function every time when the @Input is changed. I tried to do it that way:
ngOnChanges(changes: { [propName: string]: SimpleChange }) {
if( changes['inputName'] && changes['inputName'].previousValue != changes['inputName'].currentValue ) {
this.func();
}
}
but my problem is: my @Input value is'nt necessarily changed (it can be "a" and another once "a") but even if it's not changed I want to exec the function. what can I do?
Upvotes: 0
Views: 156
Reputation: 25
I solved the problem by putting object in the @Input parameter instead of string only. and now it is changed every time I change it.
Upvotes: 0
Reputation: 3387
You need to call setter method For @Input() changed everytime..
@Input('inputName') set cmpRef (cmp : any){
// your function call here goes every time @Input() changes, this setter method is called.
this.func();
}
Upvotes: 2