eventemitter - Angular 4 Component to Component Communication -
i'm sending api call on app.component.ts , emitting change, can emitted value in in child components. working fine until router redirect comes. after router redirects data not rendering since not emitted. believe because there no change detected. when refresh page data available. there workaround 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 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
Comments
Post a Comment