ngrx

Ngrx testing - How to configure TestBed in order to instantiate the entire state store in a test

时光怂恿深爱的人放手 提交于 2019-12-11 13:47:28
问题 I want to run some integration tests for the ngrx 4 state store in an Angular 5 app. My desire is to test dispatching ngrx actions, effects, webapi, mock server and selectors all together in one shot. Writting separate tests for effects and reducers is going to be a time sink and I need to cut some corners. I only need to know when one of my pages fails not the exact spot. I managed to do this in a previous project while using redux together with Angular 2. That was quite easy to setup.

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

How to guarantee the continuity of observable stream in case of http errors?

北战南征 提交于 2019-12-11 09:50:19
问题 I have a problem with the below method ( onTrySignin ) when I encounter an HTTP error response. The catch block right after my HTTP call prevents the Side Effect from throwing an Action error. if I do console.log I get this error. TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. how can I preserve the Observable stream and pass the response to the next block ( mergeMap ) where I can fire other Actions , ( FailedSignin

current state in ngrx angular

余生长醉 提交于 2019-12-11 09:10:19
问题 Hi new to ngrx i am trying implement a smaple example for ngrx with angular but i have implemented everything not able to get the current state after service call So can please help me to get the current state and how many to get the state in ngrx as newbie to ngrx and correct if there are coding needs to improved in other places I have added the stackblitz link https://stackblitz.com/edit/angular-gvjoju 回答1: The reducers added to StoreModule.forRoot() must be an actionmap, for example:

NGRX - how to have calculated properties on items in the store

孤者浪人 提交于 2019-12-11 09:08:28
问题 We're using NGRX in our Angular applications. Data is coming from an API. Certain properties come from the API as an unformatted string, so we need to format this. Of course this can be done in the HTML, but the problem is that the value is required in multiple locations, in both HTML as well as in TypeScript. So, initially we created getters for these display properties on our domain objects, but it is not supported by ngrx to store complex objects in the store as they are not serializable.

Angular observable behavior odd when shared

房东的猫 提交于 2019-12-11 08:12:54
问题 I have an observable that when I use the rxjs 'share' operator behaves strangely in the Angular template. Here's how I setup my two observables (in a service): this.family = this.store.select(getFamily).pipe( tap(family => { if (family == null) { this.loadFamily(); } }), filter(family => family != null), share(), ); this.familyMembers = this.family.pipe( map(family => { return family.familyMembers; }) ); I then add the familyMember observable to my component as a property this.familyMembers =

Angular interpolated value not updating on subscription

烈酒焚心 提交于 2019-12-11 08:08:05
问题 Angular 6.0.1 ngRx 6.0.1 I have an interpolated value set up in my View: {{firstName}} It is not updating when the value of the field it is bound to changes. The value is changing though - if I log it out to the console inside the subscription, I see the updated value. It just doesn't update in the UI. Here's the relevant code: Subscription from my component: private subscribeToCurrentPerson(): void { this.tState$ = this.store .pipe(select(selectors.getCurrentPerson), takeWhile(() => this

ngrx subscribed store does not update on state change Angular5

那年仲夏 提交于 2019-12-11 07:29:49
问题 I'm build an app that takes the name of a city sends to an api end point and returns the weather for that city. It uses an two Actions, one that will update the cities, using the name as the payload, Action two loads the new array returned to update the state The effect uses switchMap to map the api call then return results. The select function, to display results of the store, only detects the store updates on initiation of page load (Empty array) and for the first set of results And does

Can I use object spread syntax in angular + ngrx?

倾然丶 夕夏残阳落幕 提交于 2019-12-11 07:17:24
问题 I was reading from here about the object spread syntax and I'm trying to use it in my project, my setup is the following: angular 2 angular/cli 1.0.0-rc.0 ngrx/core 1.2.0 ngrx/store 2.2.1 rxjs 5.1.0 typescript 2.0.10 In my reducer.ts I have export interface State { [id: number]: string } export function reducer(state= {}, action: Action): State { case 'TEST': return { ...state, 2: 'foo' } } But I got the following compiling error, I'm trying to figure out what's wrong: Property assignment

How to have the `searchTerm` input field being observed for its value change?

ぃ、小莉子 提交于 2019-12-11 06:32:51
问题 I have two observables that work fine: @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; ngOnInit() { ... merge(this.sort.sortChange, this.paginator.page) .pipe( startWith({}), switchMap(() => { return this.getUsers(this.sort.active, this.sort.direction, this.paginator.pageIndex); }), map(userApi => { This allows for the getUsers service method to be called when the sorting or the pagination is updated. Now, I'd like to also have this service method being