angular - 在路由中传递自定义类型作为参数 -> 返回:[object Object]
问题描述
单击链接时,我需要将自定义类型的变量传递给非子/父组件。
自定义类型
export class Dati {
fileJson;
ricette: string[][];
n_Ricette: 0;
nPostazioni: number;
postazioniNome: string[];
defPostazione = "FRIGGITRICI";
}
及其在app.component.ts中的初始化:
dati : Dati = {
fileJson: "",
ricette: [[],[]],
n_Ricette: 0,
nPostazioni: 0,
postazioniNome: [],
defPostazione: "FRIGGITRICI",
}
应用程序路由模块
....
const routes: Routes = [
{ path: 'option.component/:dati', component: OptionComponent },
]
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
....
带有路由的 html 链接(app.component.html)
<a routerLink="/option.component/{{dati}}" >Opzioni</a>
option.component.ts(路由的目的地)
constructor(private route: ActivatedRoute) {
this.route.params
.subscribe(params => {
console.log(<Dati>(params["dati"]))
});
}
中的结果console.log()
是:[object Object]
。
如何获取我的数据?
附言。链接工作正常,发送的数据是正确的
解决方案
推荐阅读
- javascript - 未捕获的 TypeError 无法读取 null 的属性“类列表”
- java - 添加android项目依赖失败
- c - 当我尝试在矩阵中查找素数时,某些数字被错误地更改
- regex - 一行正则表达式与项目数无关
- c# - c# 在特定索引之后删除列表集合中的所有内容
- python - sympy:如何简化多个表达式
- javascript - 链接不使用 React DOM 路由器重定向
- java - 从命令行检查字符数
- r - 使用 Powershell 的 Rscript.exe 表达式中的双引号
- spring-mvc - 在 jboss 7 上部署 spring mvc 时出现 404 错误