ngrx angular 14 选择器不断返回 undefined

问题描述 投票:0回答:1

在构造函数之外的组件中,我有:

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 }
);
angular ngrx
1个回答
0
投票

我想您已经使用

selectUserInfo
选择了loggedInUser。
selectUserInfo
返回的实际类型是什么?如果以下不起作用,请添加选择器代码:

this.userEmail.subscribe(cc => console.log(cc?.email));
© www.soinside.com 2019 - 2024. All rights reserved.