Created
February 15, 2019 22:29
-
-
Save splincode/d5766c824d33e66c041ce657e2b57c63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class HeroesService { | |
@Select(HeroesState) | |
public data$: Observable<Hero[]>; | |
constructor( | |
private api: ApiService, | |
private spinner: NgxSpinnerService | |
) { } | |
@Dispatch() | |
public addHero(name: string, saying: string) { | |
return new AddHero({ id: AddHero.generateId(), name, saying }); | |
} | |
@Dispatch() | |
public deleteHero(id: string) { | |
return new DeleteHero(id); | |
} | |
@Dispatch() | |
public loadAll = () => { | |
this.spinner.show(); | |
return this.api.getHeroes().pipe( | |
map((heroes) => new AddHeroes(heroes)), | |
finalize(() => this.spinner.hide()) | |
) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment