ngxs

Why use NGRX instead of constructor injected services?

爷,独闯天下 提交于 2020-01-13 10:08:13
问题 Wondering why one would use NGRX or NGXS for an Angular app instead of constructor injected services to handle component IO? Is it only to ensure that component properties references are never mutated without switching out the entire property value reference or is there more to it? Altnernative to NGRX per the answer I developed: Slice. I believe it does everything NgRx / NgXS does (With the exception of a time machine - but this is easy to implement via delta notifications - already

Ngxs - Call an Angular service : good practices?

二次信任 提交于 2020-01-02 04:35:12
问题 When I use ngxs what should my app do: my component calls a service and the service dispatches an action with the result as the payload? my component dispatches an action and my State calls the service? 回答1: You can do both and if you look into open source apps you'll probably find both. So far I've personally (with ngrx but it's the same) injected the store and dispatched actions from the (smart) components. But I've been reading a lot of articles about facades lately and I think it's

Http requests made from Ngxs state doesn't get detected by Angular (zone related issue)

孤街浪徒 提交于 2019-12-18 09:51:41
问题 I'm using ngx-progressbar and it works fine with http request started from within services, components or resolvers. Note that no manual triggering of the progress bar (via service, etc) during http request is needed. It is triggered automatically. Unfortunately it doesn't work as expected when making an http request from within an NGXS State : stackblitz : I created for every case a button : "Make Request (Dispatch to store, w/o zone)" This does not work, no progress bar appears (or it

How to use patchState vs setState in NGXS?

て烟熏妆下的殇ゞ 提交于 2019-12-14 00:18:41
问题 I am learning ngxs but I can't understand when should I use patchState and setState ? What's the difference? const state = ctx.getState(); let data = this.service.list(); ctx.setState({ ...state, feedAnimals: data }); vs. let data = this.service.list(); ctx.patchState({ feedAnimals: data }); 回答1: Those two pieces of code are equivalent. patchState is just a short hand version of the setState({...state, ... } code. In future patchState will most likely be evolving to a more useful immutability

Binding to State - is this expected behaviour?

≯℡__Kan透↙ 提交于 2019-12-13 03:41:43
问题 I have a state that contains a collection of items: import { State, Action, StateContext } from '@ngxs/store'; import {AddItem} from './app.actions'; export interface Item { id: number; name: string; } export interface AppStateModel { items: Item[]; } @State<AppStateModel>({ name: 'app', defaults: { items: [] } }) export class AppState { @Action(AddItem) addItem(ctx: StateContext<AppStateModel>, action: AddItem){ const state = ctx.getState(); ctx.patchState({ items: [ ...state.items, { id:

Search / Filter State NGXS

好久不见. 提交于 2019-12-11 17:26:58
问题 I am new to NGXS and trying to integrate it into a small project. The only problem is that there are no good examples of a search / filter on state. My app gets a list of products from a backend API. It shows them by SKU on the page. I want the user to be able to type in an SKU in the input field and have the list automatically filter products as the user types. products.state.ts: @Selector() static getProductList(state: ProductStateModel) { return state.products; } @Selector() static

Where is it best to post questions about ngxs?

怎甘沉沦 提交于 2019-12-11 15:48:14
问题 I see that the ngxs tag doesn't have too many questions against it in Stack Overflow at the moment. Should I ask questions here or post a github issue here? 回答1: The way we (the ngxs team) would prefer getting questions is on stackoverflow with the ngxs tag. And only post issues (bugs) to github. By having questions on stackoverflow instead of the github issues, they don't get lost when we close the issue. If you are unsure if your problem is bug or not, it's better to post it here on

Angular - Populate form array input on edit

时光怂恿深爱的人放手 提交于 2019-12-11 12:57:53
问题 I have a quantity field and an "Add" button. On click of button new fields for quantity gets added as well as Delete button to remove it. I have used Form array for it My code is as below <div formArrayName="ingredients11"> <!-- loop throught units --> <div *ngFor="let unit of recipeForm['controls'].ingredients11['controls']; let i = index "> <div [formGroupName]="i"> <div class="form-group"> <label>Quantity</label> <input type="text" class="form-control" formControlName="recipe_ingredient

Ngxs - Call an Angular service : good practices?

不想你离开。 提交于 2019-12-05 12:09:28
When I use ngxs what should my app do: my component calls a service and the service dispatches an action with the result as the payload? my component dispatches an action and my State calls the service? You can do both and if you look into open source apps you'll probably find both. So far I've personally (with ngrx but it's the same) injected the store and dispatched actions from the (smart) components. But I've been reading a lot of articles about facades lately and I think it's actually the right way to go in order to keep your components as simple as possible but especially to simplify the

Why use NGRX instead of constructor injected services?

泪湿孤枕 提交于 2019-12-05 08:22:45
Wondering why one would use NGRX or NGXS for an Angular app instead of constructor injected services to handle component IO? Is it only to ensure that component properties references are never mutated without switching out the entire property value reference or is there more to it? Altnernative to NGRX per the answer I developed: Slice . I believe it does everything NgRx / NgXS does (With the exception of a time machine - but this is easy to implement via delta notifications - already supported). but with zero boilerplate. Here's an article showcasing some of the capabilities: https://medium