【发布时间】:2020-10-26 18:41:24
【问题描述】:
这是我的代码块。在这里,我试图将 checkinFrom 日期对象作为 routerLink 中的参数获取到另一个组件。
<app-chart-chip [routerLink]="['/statistics/subsegment',currentPS,checkinFrom]"
[currentPS]="currentPS" [fromDate]="checkinFrom">
</app-chart-chip>
这是我的父组件代码。
currentPS: string;
checkinFrom = new Date(2019, 8, 1);
ngOnInit() {
this.currentPS = 'PS';
}
这是子组件代码
export class ChartChipComponent implements OnInit, OnChanges{
@Input() fromDate = new Date();
@Input() currentPS: string;
}
这是 app.routing.module.ts 文件
{
path: 'statistics/subsegment/:currentPS/:fromDate',
component: StatisticsComponent,
loadChildren: 'src/app/statistics/statistics.module#StatisticsModule',
data: {
title: 'Subsegmentation'
}
}
对于这个组件,我试图在 URL 中的 routerLink 中获取日期作为参数
export class StatisticsComponent implements OnInit {
ngOnInit() {
this.getParticularId();
}
getParticularId() {
this.route.params.subscribe( params => {
console.log(params);
}
}
但它正在重定向到仪表板。
{
path: '**',
redirectTo: 'dashboard',
pathMatch: 'full'
}
【问题讨论】:
标签: angular typescript url routes