可以使用从NGRX Store收集的数据创建一个类型接口的对象
我有这个接口:
export interface AuthStateInterface {
isSubmitting: boolean,
X_HI_CODE: string,
token: string,
userId : number,
roleId: number
}
我想创建一个接口类型的对象,并使用其他类中的NGRX存储中收集的一些数据使用方法initializeValues()将对象创建为Bellow:
initializeValues(): void {
const data: AuthStateInterface = {
isSubmitting: false,
X_HI_CODE: this.store.pipe(select(xhicodeSelector)),
token: this.store.pipe(select(tokenSelector)),
userId : this.store.pipe(select(userIdSelector)),
roleId: this.store.pipe(select( roleIdSelector)),
};
console.log('data', data)
}
当我悬停在红色警报上时,这就是它所说的:
如果有人可以帮助我解决这个问题,我会很棒。
I have this interface:
export interface AuthStateInterface {
isSubmitting: boolean,
X_HI_CODE: string,
token: string,
userId : number,
roleId: number
}
And I want to create an object of this interface type with some data collected from the ngrx store within another class with the method initializeValues() that creates the objects as bellow:
initializeValues(): void {
const data: AuthStateInterface = {
isSubmitting: false,
X_HI_CODE: this.store.pipe(select(xhicodeSelector)),
token: this.store.pipe(select(tokenSelector)),
userId : this.store.pipe(select(userIdSelector)),
roleId: this.store.pipe(select( roleIdSelector)),
};
console.log('data', data)
}
But Visual Studio errors out as you can see on the screenshot bellow:
When I hover on the red alert, this is what it says:
I will be greatfull if anyone can help me fix this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,我误会了几个角度或打字稿的概念。正如@mikeone在评论中所说的那样,NGRX选择器返回可观察到的,我不得不订阅并将其分配给我之前声明的变量。所以这就是我所做的:
1-我初始化了变量,而不是观察到:
2-我使用selector钩3选择了来自ngrx商店的数据
3-然后我使用这些值创建传递给下一个承诺的数据
应该是做到这一点的一种较短的方法,在我的ReactJs背景下,我还有更多关于RXJ的知识,然后才吹嘘更简单的技术。但是这种方法使这项任务完成了。
There were several concepts of angular or typescript in general that I was misunderstanding. As @MikeOne said in the comments, Ngrx selectors return Observables, and I had to subscribe and assign them to the variables I've declared previously. So this is what I did:
1- I initialized the variables, not observables:
2- I selected the data from the ngrx-store with the selector hook
3- Then I used the values to create the data passed to next promise
There should be a shorter way to do it, and with my Reactjs background I had much more to learn about rxjs before boasting on simpler technics. But this approach made this task completed.