这是我的代码日期,在这里我试图将checkinFrom block.In对象作为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'
}
发布于 2020-07-06 23:50:26
在app图表芯片中添加以下代码
[queryParams]="{date:checkinFrom }"
<app-chart-chip [routerLink]="['/statistics/subsegment',currentPS,checkinFrom]"
[queryParams]="{date:checkinFrom }" [currentPS]="currentPS" [fromDate]="checkinFrom">
</app-chart-chip>
你可以像这样得到日期
new URLSearchParams(new URL('http://localhost:4400/dashboard?date=Sun%20Sep%2001%202019%2000:00:00%20GMT%2B0530%20(India%20Standard%20Time').search).get('date');
输出"Sun Sep 01 2019 00:00:00 GMT+0530 (India Standard Time"
发布于 2020-07-06 23:51:03
你传递日期的方式很好,但我认为routerLink就是错了。
试试这个:
constructor(private route: ActivatedRoute) { }
this.route.paramMap.subscribe(params => {
console.log(params)
})
HTML:
[routerLink]="['/', 'statistics', 'subsegment', currentPS,checkinFrom]"
发布于 2021-10-03 09:56:01
试试这个:
[routerLink]="['/consultation/calendar/']"
[queryParams]="{ date: lastAppointment?.startDate }"
然后:
this.route.snapshot.queryParams['date']
https://stackoverflow.com/questions/62759466
复制相似问题