Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 将对象作为参数传递到路由返回[object]_Angular_Typescript_Angular Routing_Angular Router - Fatal编程技术网

Angular 将对象作为参数传递到路由返回[object]

Angular 将对象作为参数传递到路由返回[object],angular,typescript,angular-routing,angular-router,Angular,Typescript,Angular Routing,Angular Router,这在我的routing.module中: {path: 'hero' component: HeroComponent} 这就是我通过路径传递对象的方式: this.router.createUrlTree(['/hero', {my_object: this.Obj}])); window.open(url, '_blank'); 在我的英雄组件中,我读到如下对象: this.route.snapshot.paramMap.get('my_object'); console.logthi

这在我的routing.module中:

{path: 'hero' component: HeroComponent}
这就是我通过路径传递对象的方式:

this.router.createUrlTree(['/hero', {my_object: this.Obj}]));
window.open(url, '_blank');
在我的英雄组件中,我读到如下对象:

this.route.snapshot.paramMap.get('my_object');
console.logthis.route.snapshot.paramMap.get'my_object';返回:

[Object object]
读取对象的属性,例如。id返回:

如果我尝试使用*ngFor进行迭代,我会得到:


为什么会发生这种情况?

尝试使用JSON.stringify发送字符串

this.router.createUrlTree['/hero',{my_object:JSON.stringifythis.Obj}]; 并将其解析回收件人中

this.Obj=JSON.parsethis.route.snapshot.paramMap.get'my_object'; 如果Obj变量是一个对象,则需要使用keyvalue管道使用*ngFor指令对其进行迭代

{{item.key}}:{{item.value}
尝试使用JSON.stringify发送字符串

this.router.createUrlTree['/hero',{my_object:JSON.stringifythis.Obj}]; 并将其解析回收件人中

this.Obj=JSON.parsethis.route.snapshot.paramMap.get'my_object'; 如果Obj变量是一个对象,则需要使用keyvalue管道使用*ngFor指令对其进行迭代

{{item.key}}:{{item.value}
有两种选择。1.试着像这样使用.router.createUrlTree['/hero',this.Obj];,此.Obj已经是一个对象。2.如果这不起作用,你能分享一下这个.Obj的结构吗?@piyushjain下面的答案是有效的,但是一旦我在我的组件中,我将如何检索这个.Object?this.route.snapshot.paramMap.get;?既然我以前没有属性my_对象,我应该在那里放什么?可以使用this.activatedRoute.params.subscribebeparams=>{}检索它。有两个选项。1.试着像这样使用.router.createUrlTree['/hero',this.Obj];,此.Obj已经是一个对象。2.如果这不起作用,你能分享一下这个.Obj的结构吗?@piyushjain下面的答案是有效的,但是一旦我在我的组件中,我将如何检索这个.Object?this.route.snapshot.paramMap.get;?既然我以前没有属性my_object,我应该在那里放什么呢?你可以用这个来检索它。activatedRoute.params.subscribebeparams=>{}看起来有点粗糙,但工作正常,谢谢,非常感谢
undefined
ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'string'. NgFor only supports binding to Iterables such as Arrays.