1
でリロード後に動作します。ユーザーがサインインすると、名前がナビゲーションバーに表示されません。しかし、ページをリロードすると名前が表示されます。Auth0ニックネームプロパティは、私は彼がauth0を使用してログインするときにユーザーの名前を表示したい角度の2
app.component.tsは
import { Component, AfterViewInit } from '@angular/core';
import {SignupService} from './services/signup.service';
import {Auth} from './services/auth.service';
declare var $: any;
@Component({
moduleId:module.id,
selector: 'my-app',
templateUrl: 'app.component.html',
styleUrls: ['./assets/css/navbar.css'],
providers: [SignupService],
})
export class AppComponent {
profile : any;
constructor(private auth: Auth){
this.profile=JSON.parse(localStorage.getItem('profile'));
};
ngAfterViewInit() {
$(".button-collapse").sideNav();
$(".dropdown-button").dropdown();
}
}あなたが唯一の起動時に値を収集しているためだ
私はsetTimeoutを()関数を追加する必要がありますか? –
@KarthikSKumarは 'this.profile'が視覚的にかログインされているユーザを表示する変数であり、あなたは' setTimeout'関数にその行全体をカプセル化すべきであることを考慮します。 'のsetTimeout(()=> {this.profile = JSON.parse(localStorage.getItem( 'プロフィール'));}、100);メソッドは – zurfyx
はことを確認@KarthikSKumar 'this.profile' **コントローラのテンプレート(つまり、 '{{profile.username}}')で後で表示される**変数です。それ以外の場合は、他の変数をリロードする必要があります。 –