ABP:如何获取当前用户ID?

问题描述 投票:0回答:1

我设法显示了当前用户的电子邮件,但是如何获取用户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:对不起,我的英语😂

html angular typescript abp
1个回答
0
投票

您可以使用SessionServiceProxy中的GetCurrentLoginInformations()。它返回一个对象,该对象包含UserLoginInfoDto,其中包含电子邮件,姓名等

© www.soinside.com 2019 - 2024. All rights reserved.