【问题标题】:Angular 6 nebular 6 get query param in componentAngular 6 nebular 6 获取组件中的查询参数
【发布时间】:2018-11-10 11:28:52
【问题描述】:

我正在使用带有身份验证的 Angular 6、ngx-admin 主题。我想在 url 中传递令牌 id 以重置密码,并以重置密码形式获取该 id,以便我可以将其传递给后端服务器。下面是我的 app-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”并将其传递给表单。

【问题讨论】:

    标签: angular authentication routing angular-routing


    【解决方案1】:

    先导入ActivateRoute并初始化

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-26
      • 2019-02-07
      • 2018-11-14
      • 2018-03-20
      • 1970-01-01
      • 2019-03-22
      • 2019-02-01
      • 2019-06-29
      相关资源
      最近更新 更多