Angular 6 nebular 6 获取组件中的查询参数

Angular 6 nebular 6 get query param in component

我正在使用 Angular 6,ngx-admin 主题及其身份验证。我想在 url 中传递令牌 ID 以重置密码,并以重置密码形式获取该 ID,以便我可以将其传递给后端服务器。下面是我的应用程序-routing.module.ts 文件:

{
path: 'auth',
component: NgxAuthComponent,
children: [
  {
    path: '',
    component: NgxLoginComponent,
  },
  {
    path: 'request-password',
    component: NgxRequestPasswordComponent,
  },
  {
    path: 'reset-password/:token',//here i need token
    component: NgxResetPasswordComponent,
  },

下面是 NgxResetPasswordComponent 文件:

constructor(protected service: NbAuthService,
          @Inject(NB_AUTH_OPTIONS) protected config = {},
          protected router: Router) {

this.redirectDelay = this.getConfigValue('forms.resetPassword.redirectDelay');
this.showMessages = this.getConfigValue('forms.resetPassword.showMessages');
this.provider = this.getConfigValue('forms.resetPassword.provider');

  console.log(this.router.url);//output: /auth/reset-password/dsadasdasfaf

}

我需要从这个 URL 中获取 "dsadasdasfaf" 并将其传递给表单。

先导入ActivateRoute并初始化

constructor(private activatedRoute: ActivatedRoute) {}

this.activatedRoute.params.subscribe((params: Params) => {
        let token = params['token'];
        console.log(token);
      });