Last active
March 19, 2016 09:21
-
-
Save jamesmorgan/f3f26165f63e376bd8b4 to your computer and use it in GitHub Desktop.
Example Angular2 EventEmitter in TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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