I am facing an issue with a selector that is passing data to a child component. Although the selector is functioning correctly and the child component is being constructed properly, I am encountering problems when trying to subscribe to the selector in the parent component. When I attempt to use the information for a different task, the subscribe function returns an undefined value. Can anyone help me identify where I may be going wrong?
Here is my code snippet:
size: any;
mySubscription: Subscription;
constructor(
private AppStore: Store<Store.NewState>
) { }
ngOnInit() {
this.position$ = this.AppStore.select(positionSelectors.selectPositionState);
if (!this.position$ === undefined) {
this.mySubscription = this.position$.subscribe((resp) => {
this.size = Object.keys(resp).length;
});
this.mySubscription.unsubscribe();
}
}
My goal is to retrieve the length of the response, but it seems nothing is getting past the conditional check. If I remove the condition, I receive multiple errors indicating that the Object is undefined. The specific error I am encountering is:
TypeError: Cannot convert undefined or null to object