在构造函数之外的组件中,我有:
userEmail = this.Authstate.pipe(select(selectUserInfo));
在我的构造函数中,我创建了我的状态:
this.Authstate.dispatch(unencryptEmail({ email: this.userKey }));
在我的 ngOnInit() 方法中我有:
this.userEmail.subscribe(console.log);
到目前为止一切都很好。 从状态来看,我现在只想收到电子邮件,我将 ngOnInit 方法中的订阅更改为:
this.userEmail.subscribe(cc => console.log(cc?.LoggedInUser?.email));
状态仍然相同,但现在在控制台中我得到
undefined
.
为什么我收不到邮件?
*** 更新 ****
这是我的选择器代码:
export const getAuthFeatureState = createFeatureSelector<AuthState>(authFeatureName);
export const selectUser = (state: AuthState) => state.profile;
export const selectIsAuthenticated = createSelector(
getAuthFeatureState,
(state: AuthState) => state.isLoggedIn
);
export const selectUserInfo = createSelector(
getAuthFeatureState,
(state: AuthState) => { return state.profile }
);
我想您已经使用
selectUserInfo
选择了loggedInUser。 selectUserInfo
返回的实际类型是什么?如果以下不起作用,请添加选择器代码:
this.userEmail.subscribe(cc => console.log(cc?.email));