0
我遇到了一些奇怪的问题。我有一个类:Typescript改变了属性类型?
export class Example: {
str: string;
isActive: boolean;
}
然后,我从一个组件通过routerLink
和queryParams
转让该类的一些数据到另一个......在子组件我这样做:
this.activatedRoute.params.subscribe((params: Example) => {
console.log(params, typeof params.isActive); //outputs string!!
});
//output: {str: "xxx", isActive: "true"}, "string"
第一我送queryParams模板为:
[routerLink]="['/my/route', row]"
,
然后我试图做一个控制器:
onBtnClick(row: Example) {
console.log(row, typeof row.isActive);
this.router.navigate(['/my/route'],{queryParams: row});
}
//output: {str: "xxx", isActive: true}, "boolean"
为什么会发生,以及如何解决这个问题?
什么是错误? – Chandru
布尔属性'isActive'是如何变成'string'的? – Daria