【发布时间】:2017-05-31 01:13:16
【问题描述】:
我尝试在我的 Angular 2 项目中使用 Auth0。我正在从Auth0 website 学习它。我的问题是用户个人资料。登录后,我调用 ngOnInit 的方法与网站示例中的方法大致相同:
if (this.auth.isAuthenticated()) {
if (this.auth.userProfile) {
this.profile = this.auth.userProfile;
} else {
this.auth.getProfile((err, profile) => {
this.profile = profile;
});
}
this.auth.alreadyExists(this.profile.sub);
}
问题在于this.auth.alreadyExists(this.profile.sub);方法的参数this.profile.sub。
错误信息是:
错误错误:未捕获(承诺中):TypeError:无法读取未定义的属性“子” 类型错误:无法读取未定义的属性“子”。
如果我在 HTML 文件中写入 {{profile?.sub}} 并删除 this.auth.alreadyExists(this.profile.sub); 方法,它会毫无问题地显示 user_id。
我不知道错在哪里。
谢谢!
【问题讨论】: