Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jamesmorgan/f3f26165f63e376bd8b4 to your computer and use it in GitHub Desktop.
Save jamesmorgan/f3f26165f63e376bd8b4 to your computer and use it in GitHub Desktop.
Example Angular2 EventEmitter in TypeScript
export class CompetitionsService {
/** Create a EventEmitter - constructing with true to make async */
onCompetitionsChanged = new EventEmitter<>(true);
constructor(private _http:Http) {
_http.get('competitions.json')
.subscribe(
data => {
//Broadcast the event to anyone who is listening
this.onCompetitionsChanged.emit(data.json());
},
err => console.error('Failed to load competitions', err),
() => console.log('Loaded competitions')
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment