【发布时间】:2019-11-08 04:54:01
【问题描述】:
我正在尝试从 Auth0 获取用户个人资料信息。它使用管道异步在前端工作
<pre *ngIf="auth.userProfile$ | async as profile">
<code>{{ profile | json }}</code>
</pre>
但是在后端如果我想读取昵称并用它做点什么。我迷路了。
constructor(public auth: AuthService)
ngOnInit() {
if (this.auth.isAuthenticated$) {
const result = this.auth.userProfile$;
}
}
我知道我的变量“结果”是一个 Observable。 但我对 Observable 的这些东西很陌生。我试图获得价值。 如果我使用调试控制台,我可以看到这一行的值:
this.auth.userProfile$.source.value.nickname
但是如果我在我的代码中编写它,我有这个错误:Typescript error: Property 'value' does not exist on type 'Observable'
ngOnInit() {
if (this.auth.isAuthenticated$) {
const result = this.auth.userProfile$;
console.log(this.auth.userProfile$.source.value.nickname); // error here
}
}
所以有人可以帮助我吗? 谢谢
【问题讨论】:
标签: auth0