When you want to run some code after the component/directive inputs changes you can use setters or ngOnChanges hook, but what are the benefits of using one on the other? Or they are the same thing exactly?
ngOnChanges
@Input() set someInput( val ) { this.runSomething(); } ngOnChanges(changes) { this.runSomething(); }
One advantage of ngOnChanges() is that you get all changes at once if your component has several @Input()s. If your code only depends on a single @Input() a setter is probably the better approach.
ngOnChanges()
@Input()
1.4m articles
1.4m replys
5 comments
57.0k users