Угловой 6 небулярный 6 получить параметр запроса в компоненте - PullRequest
0 голосов
/ 31 мая 2018

Я использую Angular 6, тему ngx-admin с аутентификацией.Я хочу передать идентификатор токена в URL для сброса пароля и получить этот идентификатор в форме пароля для сброса, чтобы я мог передать его на внутренний сервер.Ниже приведен мой файл 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

}

Мне нужно получить «dsadasdasfaf» с этого URL и передать егоформа.

1 Ответ

0 голосов
/ 31 мая 2018

Сначала импортируйте ActivateRoute и инициализируйте его

constructor(private activatedRoute: ActivatedRoute) {}

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