我有一个父组件(CategoryComponent),一个子组件(videoListComponent)和一个ApiService.
我有大部分工作正常,即每个组件可以访问json api并通过observable获取其相关数据.
目前视频列表组件只是获取所有视频,我想将其过滤为特定类别中的视频,我通过将categoryId传递给子项来实现此目的@Input().
CategoryComponent.html
<video-list *ngIf="category" [categoryId]="category.id"></video-list>
Run Code Online (Sandbox Code Playgroud)
这有效,当父CategoryComponent类别更改时,categoryId值将通过via传递,@Input()但我需要在VideoListComponent中检测到这一点并通过APIService(使用新的categoryId)重新请求视频数组.
在AngularJS中,我会对$watch变量做一个.处理这个问题的最佳方法是什么?