Created
January 28, 2019 17:46
-
-
Save Oleg-Sulzhenko/bf5f7dad0c08c938099f1ec698f3edd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There are three ways to do this: | |
1) Put an *ngIf in parent. Only render child when parent's items is ready. | |
<div *ngIf="items"> | |
<child [items]="items | async"> | |
</div> | |
2) Separate your input getter setter in child. Then act whenever the value is set, you can use RxJS BehaviorSubject also. | |
private _items = new BehaviorSubject<Items[]>([]); | |
@Input() set items(value: Items[]) { | |
this._items.next(value); | |
} | |
get items() { | |
return this._items.getValue(); | |
} | |
ngOnInit() { | |
this._items.subscribe(x => { | |
this.chunk(x); | |
}) | |
} | |
3) Do it during the ngOnChanges of the child. | |
Refer to here for example. https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html#!#onchanges | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment