I have reactive Form Angular application using NGRX store. Rather than subscribe to entire state want to subscribe some of fields changes e.g. name,city.
I am trying to selectFormNameCity selector but always its subscribing for single properties.
Tried both OR and AND operator condition in selector but not working as expected.
How to achieve using single selector selectFormNameCity for name and city if one of the value changed should get subscribe in component.
Here is the code stackblitz example.
import { createFeatureSelector, createSelector } from '@ngrx/store';
export const selectForm = createFeatureSelector<any>('form');
export const name = createSelector(selectForm, (state) => state.info.name);
export const city = createSelector(selectForm, (state) => state.info.city);
export const selectFormNameCity = createSelector(name, city, (name, city) => {
return { name, city };
});
Thanks.
I didn’t get your use case, but it will work if you change the selector a bit:
export const selectFormNameCity = createSelector(name, city, (name, city) => {
return {name, city};
});
And it will give you the next output:
{name: "vvvv", city: ""}
{name: "vvvv", city: "123213"}
{name: "44vvvv", city: "123213"}