在路由中传递令牌参数,并在组件中获取该令牌并将其设置为文本输入字段的值。
示例代码:
在路由中定义参数:
const routes: Routes = [
{ path: 'confirmation/:token', component: ConfirmationComponent }
];
在组件中获取令牌参数并设置为文本输入字段的值:
import { ActivatedRoute } from '@angular/router';
export class ConfirmationComponent implements OnInit {
token: string;
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.token = this.route.snapshot.paramMap.get('token');
}
}
在模板中将令牌设置为文本输入字段的值: