Tag: angular2 changedetection

如何在Angular2中检测@Input()值的变化

我有一个父组件( CategoryComponent ),一个子组件( videoListComponent )和一个ApiService。 我大部分工作正常,即每个组件可以访问JSON API,并通过observables获取其相关数据。 目前的video列表组件只是获取所有的video,我想过滤这只是一个特定类别的video,我通过@Input()将categoryId传递给孩子来实现这一点。 CategoryComponent.html <video-list *ngIf="category" [categoryId]="category.id"></video-list> 这工作,当父类CategoryComponent类别更改然后categoryId值通过@Input()传递但我需要在VideoListComponent中检测到此并通过APIService(具有新的categoryId)重新请求video数组。 在angular1中,我会在variables上做一个$watch 。 处理这个问题的最好方法是什么?

什么是Angular2等同于AngularJS $手表?

在AngularJS中,您可以使用$watch scope的$watch函数指定观察者观察范围variables的变化。 在Angular2中观察variables变化(例如,组件variables)的等价物是什么?