【发布时间】:2016-11-29 00:50:49
【问题描述】:
我有一个父组件 (CategoryComponent)、一个子组件 (videoListComponent) 和一个 ApiService。
我的大部分工作都很好,即每个组件都可以访问 json api 并通过 observables 获取其相关数据。
目前视频列表组件只获取所有视频,我想将其过滤为特定类别中的视频,我通过将 categoryId 通过@Input() 传递给孩子来实现这一点。
CategoryComponent.html
<video-list *ngIf="category" [categoryId]="category.id"></video-list>
这可行,当父 CategoryComponent 类别发生变化时,categoryId 值通过 @Input() 传递,但我需要在 VideoListComponent 中检测到这一点,并通过 APIService 重新请求视频数组(使用新的 categoryId)。
在 AngularJS 中,我会在变量上执行 $watch。处理这个问题的最佳方法是什么?
【问题讨论】:
标签: angular angular2-changedetection angular-decorator