I want the cars object in the customer class to be empty instead of undefined as I have selectors to select the cars object and I want it to return empty rather than undefined.
Here is my initial state.
export const initialState: CustomerState = {
customer: new Customer(),
};
export class Customer{
id: number;
age: number;
cars: carClass;
phoneNumbers: string[];
}
export class carClass{
name:string;
citiesRegistered:city[];
}
export class city{
parks: string[],
lakes: string[],
schools: string[]
}
Here is my reducer with selector.
const getCustomerState= createFeatureSelector<CustomerState>('customer');
export const getCustomerCarsCities = createSelector(
getCustomerState,
state => state.customer.cars.citiesRegistered // There is an error here
);
Here is the component to get cities registered
getCustomerCitiesRegistered$: Observable<any>;
constructor(private store: Store) {
this.getCustomerCitiesRegistered$ = this.store.select(getCustomerCarsCities );
}
Here is the html
<div *ngIf="getCustomerCitiesRegistered$ | async as cities"> // This is undefined
<div class="parks">
<app-parks [parkOptions]="cities.parks">
</parks>
</div>
</div>
I get an error that cities is undefined. How can I get an empty object if the state is empty