My setup involves having 2 subscriptions - one is related to my ActivatedRoute, and the other is from ngrx Store.
ngOnInit() {
this.menuItems$ = this.store.select('menuItems');
this.menuItems$.subscribe(data => {
this.menuItems = data.menuItems;
});
}
ngAfterViewInit() {
this.fragmentSubscription = this.route.fragment.pipe(
filter((fragment: string) => typeof fragment === 'string')
).subscribe((fragment: string) => {
setTimeout(() => {
const element: ElementRef = this.menuItems.find(menuItem => menuItem.link === fragment).element;
if(element !== undefined) {
element.nativeElement.scrollIntoView({ behavior: "smooth", block: "start", inline: "center" });
}
});
});
}
Due to a dependency between my ActivatedRoute (fragment) subscription and my store subscription data, I need to delay the former until the latter has been successfully subscribed for the first time.
Is there an rxjs operator that can help achieve this?
Thanks