0

I'm sending an API call on app.component.ts and emitting the change, so i can get the emitted value in the in the child components. Everything is working fine until a router redirect comes. After the router redirects the data is not rendering since it is not emitted. I believe this is because there is no change detected. when i refresh the page data is available. Is there any workaround to get the data.

app.component.ts

  ngOnInit() {
      this._ApiConnectorService.getQuestions().subscribe(res => {
      this._EmittersService.sendQuestion(res) })
  }
 }

summary.component.ts

ngOnInit() {
   this._EmittersService.qustionEmitted$.subscribe(obj => {
     this.questionSummary = obj;
  }
}

Emitter Function

private emitQuestion = new Subject<any>();
qustionEmitted$ = this.emitQuestion.asObservable();
sendQuestion(change: any) {
  this.emitQuestion.next(change);
}

I'm calling the summary component via button click.

<button *ngIf="allAnswered" class="btn btn-view-summary" routerLink="/summary">  
  View Summary
</button>

Please guide me on this

Thanks in advance

sinthu225
  • 301
  • 3
  • 16

0 Answers0