ng add @ngxs/schematicsGénérer 2 fichiers : .actions.ts & .state.ts
ng generate @ngxs/schematics:store --name appexport class GetAllTeams {
static type = 'Get all teams';
constructor() {}
} @Action(GetAllTeams)
getAllTeams(ctx: StateContext<FutStateModel>) {
return this.service.getAllTeams().subscribe((data: Team) => {
if (data) {
ctx.patchState({
teams: Object.assign([], data)
});
}
});
}ctx.dispatch(new GetAllTeams()); @Selector()
static getTeam(state: FutStateModel) {
return state.teams;
} @Select(FutState.getTeam)
teams$: Observable<Team>;this.teams$.subscribe((data: Team) => {
if (data) {
this.team = data;
}
}); this.action.pipe(ofActionSuccessful(UpdateUser)).subscribe(() => {
this.store.dispatch(new Signin(this.userUpdate.login, this.userUpdate.password))
this.profileUpdate = true;
this.initForm();
this.toastr.success(this.translator.instant('UPDATE.SUCCESS'));
})
//ofActionDispatched: triggers when an action has been dispatched
//ofActionSuccessful: triggers when an action has been completed successfully
//ofActionCanceled: triggers when an action has been canceled
//ofActionErrored: triggers when an action has caused an error to be thrown
//ofActionCompleted: triggers when an action has been completed whether it was successful or not