我设法显示了当前用户的电子邮件,但是如何获取用户ID?
Template:
<div *ngIf="!hasLoggedIn">
{{ (profile$ | async)?.email }}
</div>
TypeScript:
import { Profile, GetProfile, ProfileState, } from '@abp/ng.core';
export class Component implements OnInit {
@Select(ProfileState.getProfile) //State
profile$: Observable<Profile.Response>; //Model
get hasLoggedIn(): boolean {
return this.oAuthService.hasValidAccessToken();
}
constructor(private oAuthService: OAuthService) {}
ngOnInit() {
this.store.dispatch(new GetProfile()).subscribe(); //Action
}
}
在app-routing.module.ts
里面有ApplicationLayoutComponent
的导入,在里面有一个变量currentUser $: Observable <ApplicationConfiguration.CurrentUser>;
的声明,该变量用于在导航栏中显示用户名,在ApplicationConfiguration
模型内有一个ID,但我无法像使用电子邮件一样实施]
Ps:对不起,我的英语😂
您可以使用SessionServiceProxy中的GetCurrentLoginInformations()。它返回一个对象,该对象包含UserLoginInfoDto,其中包含电子邮件,姓名等