Answer the question
In order to leave comments, you need to log in
Why is Angular service returning null?
Why is Null being passed to the component?
sidebar item click sidebar.component
onChangeItemAction(item:NavItem){
console.log('выбранный '+item.name + ' ' + item.id)
this.shareService.setItemNav(item);
}
item_nav$: BehaviorSubject<NavItem> = new BehaviorSubject<NavItem>(null);
setItemNav(value:NavItem){
this.item_nav$.next(value);
console.log("вставлена в сервис" + value.name)
}
private subscriptions: Subscription[]=[];
nav_item:NavItem;
ngOnInit(): void {
const item = this.shareService.item_nav$.subscribe((data:NavItem)=>{
this.nav_item = data;
console.log(this.shareService.item_nav$.getValue());
console.log(this.nav_item)
});
this.subscriptions.push(item);
}
ngOnDestroy(): void {
this.subscriptions.forEach(s=>s.unsubscribe());
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question