我使用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
}
我需要得到" dsadasdasfaf"从此URL并将其传递给表单。
答案 0 :(得分:2)
首先导入var data = [{
id: 1,
type: 'smartphone',
details: [{
brand: 'Samsung',
model: 'Galaxy A5'
}]
},
{
id: 2,
type: 'smartphone',
details: [{
brand: 'iPhone',
model: '6 plus'
}]
},
{
id: 3,
type: 'smartphone',
details: [{
brand: 'Samsung',
model: 'Galaxy A5'
}]
},
{
id: 4,
type: 'smartphone',
details: [{
brand: 'iPhone',
model: '7 plus'
}]
},
{
id: 5,
type: 'phone',
details: [{
brand: 'Nokia',
model: '3310'
}]
},
{
id: 6,
type: 'smartphone',
details: [{
brand: 'Samsung',
model: 'Galaxy A5'
}]
},
{
id: 7,
type: 'smartphone',
details: [{
brand: 'iPhone',
model: '6 plus'
}]
}
]
var reduced = data.reduce((acc, eachElem) => {
var foundIndex = acc.findIndex((e) => {
return eachElem.type == e.type && eachElem.details[0].brand == e.details[0].brand && eachElem.details[0].model == e.details[0].model;
});
if (foundIndex === -1) {
eachElem["count"] = 1;
acc.push(eachElem);
}
else {
acc[foundIndex]['count']++
}
return acc;
}, [])
console.log(reduced);
并初始化
ActivateRoute