Here is my code:
App.component
ngOnInit() {
this.favoritesServ.addFavoriteEvent
.subscribe(data => this.name = data)
}
Service
addFavoriteEvent = new EventEmitter();
pushData(value) {
this.addFavoriteEvent.emit(value)
}
Here is my code:
App.component
ngOnInit() {
this.favoritesServ.addFavoriteEvent
.subscribe(data => this.name = data)
}
Service
addFavoriteEvent = new EventEmitter();
pushData(value) {
this.addFavoriteEvent.emit(value)
}
Use an Observable or Promise for your purpose.
Also, according to Angular2 style guide, don't abbreviate class names or properties.
A very simple example would be:
Service:
private observer; //an observer that 'emits' values to the Observable
addFavoriteEvent : Observable<any> = new Observable<any>(observer => this.observer = observer);
//create an instance of an Observable and assign the created observer to our local observer for easy re-usage.
pushData(value) {
this.observer.next(value);
}
Your component may stay unchanged.