使用Angular 2和打字稿.我有一个数组,我使用DoCheck和IterableDiffer来监听我的代码中的更改.当数组被更改时,我收到通知,但是当数组中某个对象内的属性发生更改时,我不会收到通知.我尝试使用KeyValueDiffer,但它不起作用.我想也许我需要以不同方式使用"_differs.find".有任何想法吗?
@Component({
selector: 'test'
})
@View({
template: `
<div>hello!</div>`
})
export class MyComponent implements DoCheck {
private _differ: IterableDiffer;
private _differ2: KeyValueDiffer;
_myItems: MyItem[];
@Input()
set myItems(value: MyItem[]) {
this._myItems = value;
if (!this._differ && value) {
this._differ = this._iterableDiffers.find([]).create(null);
}
if (!this._differ2 && value) {
this._differ2 = this._differs.find(this._myItems).create(null);
}
}
get myItems() {
return this._myItems;
}
constructor(private _iterableDiffers: IterableDiffers, private _differs: KeyValueDiffers, private _myService: MyService) {
this.myItems = _myService.getItems();
}
ngDoCheck() {
var changes = this._differ.diff(this._myItems);
if (changes) …Run Code Online (Sandbox Code Playgroud)