Angular 2 setters vs ngOnChanges

前端 未结 1 1814
有刺的猬
有刺的猬 2021-01-31 15:07

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 o

相关标签:
1条回答
  • 2021-01-31 15:18

    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.

    0 讨论(0)
提交回复
热议问题