Injectable Actions

Starting from version 9.1.0 @ng-state/store supports injectable actions with possibilit to inject an Angular service into constructor. This pushes even further separation of concerns by moving not only state manipulation logic inside actions but also data retrieval, logging and other related functionality.

@Injectable({ providedIn: 'root' })
@InjectStore('users')
export class TodosStateActions extends HasSignalStore<TodoModel[]> {
    constructor(private userService: DataService) {
        super();
    }

    getUsers() {
        this.userService.getData().subscribe(() => {
            this.store.update(state => {
                state.users.push(...state);
            });
        });
       
    }
}

Due to Angular injection Injectabel actions cannot be used with decorators and state actions

Last updated