I am trying to iterate on an Observable of the RxJS store state by using:
ngOnInit() {
this.route.params
.subscribe(
(params: Params) => {
this.index = +params['propertyId'];
this.propertyState = this.store.select('propertyState');
if (Number.isInteger(this.index)) {
this.store.dispatch(new fromPropertyAction.SelectProperty(this.index));
}
}
);
}
HTML: *ngFor="let property of (propertyState | async).properties; let i = index" (click)="onSelectProperty(i)"
And also tried:
ngOnInit() {
this.route.params
.subscribe(
(params: Params) => {
this.index = +params['propertyId'];
this.store.select('propertyState').subscribe(data => {
this.properties = data.properties;
})
if (Number.isInteger(this.index)) {
this.store.dispatch(new fromPropertyAction.SelectProperty(this.index));
}
}
);
}
HTML: *ngFor="let property of properties; let i = index"
But both cases I get this error.
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
Also, store here is declared in the constructor of type: private store: Store
fromApp.AppState is in the app reducer:
export interface AppState {
propertyState: fromPropertyReducer.State
}
fromPropertyReducer.State is in the property reducer:
export interface State {
properties: Property[];
selectedProperty: Property;
selectedPropertyIndex: number;
openAllProperties: boolean;
selectedPropertyExpenseIndex: number;
}
Also, initially the properties shows up fine in the html iterating over the array. But after an action to add a new expense to the property.expenses array, does this error occur. This is how I am adding the new expense in the reducer:
case PropertyListActions.ADD_PROPERTY_EXPENSE:
let property = state.properties[state.selectedPropertyIndex];
const updatedExpenses = [
...property.expenses,
action.payload
];
const updatedProperty = {
...property,
expenses: updatedExpenses
};
const updatedProperties = {
...state.properties,
};
updatedProperties[state.selectedPropertyIndex] = updatedProperty;
return {
...state,
properties: updatedProperties
}
I looked at others' post so tried the second method but didn't work. Please help. Thank you.
datalook like. - Praveen Soni