1 year ago
#387088
Muthulakshmi M
Angular8 - BehaviorSubject rxjs
My Provider:
organizationMenuLoaded: Observable<ContentResponse>;
private _organizationMenuLoadedSubject: BehaviorSubject<ContentResponse>;
private _organizationMenu: ContentResponse;
getOrganizationMenu() {
this._organizationMenuLoadedSubject = <BehaviorSubject<ContentResponse>>new BehaviorSubject(new ContentResponse());
this.organizationMenuLoaded = this._organizationMenuLoadedSubject.asObservable();
this.commonServices.getOrganizationMenu().pipe(map((response) => {
var results = response['result'];
var contentResponse = new ContentResponse();
contentResponse.Menus = results;
return contentResponse;
})).subscribe((subscription) => {
this._organizationMenu = subscription;
this._organizationMenuLoadedSubject.next(Object.assign({}, this._organizationMenu));
});
}
My Login Componenet
constructor(
private organizationMenuProvider: OrganizationMenuProvider,
) { }
loginSuccess(){
this.organizationMenuProvider.getOrganizationMenu()
}
MyCurrentComponent
constructor(
private organizationMenuProvider: OrganizationMenuProvider,
) { }
getDataList(){
this.organizationMenuProvider.organizationMenuLoaded.subscribe(
data => {
console.log(data);
});
}
When I am using console.log(this.organizationMenuProvider.organizationMenuLoaded) in both Provider and Login component, the value was updated but in MycurrentComponent the value was not updated. It's maintaining old value until we refresh the page. Can anyone suggest me what i have done wrong. Your answer is more valuable. Thanks in advance.
angular
typescript
rxjs
components
0 Answers
Your Answer