I\'m passing async data from a parent component to a child component. And the child component needs to know the length of the data in order to do something.
How the
There are three ways to do this:
*ngIf in parent. Only render child when parent's items is ready.
getter setter in child. Then act whenever the value is set, you can use RxJS BehaviorSubject also.private _items = new BehaviorSubject([]);
@Input() set items(value: Items[]) {
this._items.next(value);
}
get items() {
return this._items.getValue();
}
ngOnInit() {
this._items.subscribe(x => {
this.chunk(x);
})
}
ngOnChanges of the child. Refer to here for example. https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html#!#onchanges