Skip to content

Instantly share code, notes, and snippets.

@pjlamb12
Last active July 18, 2016 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjlamb12/c3f6633008093eb268fd5b2f618c0934 to your computer and use it in GitHub Desktop.
Save pjlamb12/c3f6633008093eb268fd5b2f618c0934 to your computer and use it in GitHub Desktop.
The child component's output event is called if you call the component's onTestOutputButtonClick() function directly, but if you try and emit an event from inside the service's callback, no event is emitted.
//Component Declaration
export class ChildComponent {
@Output() onOutputEvt: EventEmitter<any> = new EventEmitter<any>();
onTestOutputButtonClick() {
this.onOutputEvt.emit({data: 'Emitted data'});
}
makeAnUpdate(form) {
this._service.makeDbCall(data).subscribe(result => {
this.variable = result;
this.onOutputEvt.emit({data: 'Emitted data'});
});
}
}
<child-component (onOutputEvt)="handleChildOutput($event)"></child-component>
//Component declaration
export class ParentComponent {
handleChildOutput(outputData: any) {
console.log('I received output from the child component');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment