I have this ngAfterViewInit lifecycle hook:
ngAfterViewInit() {
this.sort.sortChange.subscribe(() => this.paginator.pageIndex = 0);
this.subscription = this.dataService.dataChanged
.subscribe(
() => {
this.getData();
}
);
this.getData();
}
I want the subscription to run before the this.getData()
that's outside the subscription, and only if that didn't happen, I would like for the this.getData()
that's outside the subscription to run.
How can I make that happen? Putting it in ngOnInit doesn't work because this is a paginated table and that only works after the page has been rendered. I need to have the subscription for when the user adds new data to the table and I want it to be visible automatically.
Edited If I run the code like it is written above, then when first navigating to the page, my data is correctly loaded to my paginated table from the server. Then, the user can add a new data item, using a form that's in another component. When the user is done adding the new item, they are navigated back to this table. The way it looks now, the table is first loaded without the new addition, and is then reloaded with the new addition. What I wanted to happen is for the first loading to not be visible to the user - so that when they are navigated back, they see the correct data right away.