Called Api Once and used many component in Angular 4?

65 views Asked by At

I have two component Master and MasterDetails and one service name MasterService when first time load master component its working fine but if I navigate to MasterDetails component then I get blank response how to resolve it please suggest me

Master Component

this.masterservice.abc(this.userid).subscribe(res => {
  this.shohinEditData = res;
  // set shohinEdit data in global variable
  this.masterservice.setUserInfo(this.shohinEditData);
}

MasterDetails Component

constructor(private masterservice: MasterService){
  this.masterservice.currentuserInfo.subscribe((userInfo) =>{(console.log(userInfo))});
}

MasterService

private userInfo = new BehaviorSubject('');
currentuserInfo = this.userInfo.asObservable();


setuserInfo(userInfo: any) {
  this.userInfo.next(userInfo);
}
0

There are 0 answers