所以我一直在auth0网站上关于如何为我的应用程序构建用户配置文件系统的教程,但我无法让它完全正常工作。我已经达到了我的登录工作正常的程度,但是当将数据提取到用户配置文件中时,它只是不想工作。不知道从哪里去。
使用https://auth0.com/docs/quickstart/spa/angular2/02-user-profile
的教程我的代码目前是
profile.components.html
rawEnvironmentFromLocalStore()
profile.components.ts
<div class="panel panel-default profile-area">
<div class="panel-heading">
<h3>Profile</h3>
</div>
<div class="panel-body">
<img src="{{profile?.picture}}" class="avatar" alt="avatar">
<div>
<label><i class="glyphicon glyphicon-user"></i> Nickname</label>
<h3 class="nickname">{{ profile?.nickname }}</h3>
</div>
<pre class="full-profile">{{ profile | json }}</pre>
</div>
</div>
authentication.service.ts
import { Component, OnInit } from '@angular/core';
import { AuthenticationService } from './../services/authentication.service';
interface User {
id: number,
name: string,
image: string
}
@Component({
selector: 'db-profile',
templateUrl: 'app/profile/profile.component.html'
})
export class ProfileComponent implements OnInit {
profile: any;
constructor(public auth: AuthenticationService) { }
ngOnInit() {
if (this.auth.userProfile) {
this.profile = this.auth.userProfile;
} else {
this.auth.getProfile((err, profile) => {
this.profile = profile;
});
}
}
}
答案 0 :(得分:0)
您可能想尝试这个
constructor(private auth: Auth) {
this.profile = JSON.parse(localStorage.getItem('profile'));
this.token = localStorage.getItem('id_token');
console.log(this.profile);
}