Angular 2可以沿路由器传递复杂对象吗?
发布时间:2020-12-17 17:42:30 所属栏目:安全 来源:网络整理
导读:是否可以通过路由器发送复杂对象? 这是我正在做的和尝试做的事情: 在搜索页面中,用户可以单击其中一个结果上的按钮,该结果调用导致此行触发的方法. this.router.navigate([‘profile-detail’,selection]); 选择对象在导航之前就像这样. { profile: { id:
是否可以通过路由器发送复杂对象?
这是我正在做的和尝试做的事情: 在搜索页面中,用户可以单击其中一个结果上的按钮,该结果调用导致此行触发的方法. this.router.navigate([‘profile-detail’,selection]); 选择对象在导航之前就像这样. { profile: { id: number,fname: string,lname: string },contact: { type: string,address: string },books: [{ title: string,author: string }] } 但是,当我们到达profile-detail页面时,this.route.snapshot.params将此作为实际数据: { profile: "[object Object]",contact: "[object Object]",books: "[object Object]" } 解决方法
不,路由器需要将数据序列化到浏览器URL栏,并且URL栏仅支持字符串.
您可以使用共享服务在不是父/子或兄弟节点的组件之间传递对象,也可以像路由器那样动态添加对象. 另见https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service 根据您的具体要求https://angular.io/docs/ts/latest/guide/router.html#!#resolve-guard,解析器也可能有效 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |