【发布时间】:2017-07-29 21:06:56
【问题描述】:
我正在尝试从另一个视图获取数据,如下所示:
this.paramsSub = this.activatedRoute.params.subscribe(params => this.categories = params['obj']);
this.paramsSub = this.activatedRoute.params.subscribe(params => this.userInfo = params['usr']);
数据是这样发送的:
this.router.navigate(['/path/obj', {obj: this.categories, usr: this.userInfo}]);
我正在尝试在 html 中显示带有 *ngFor 的类别,如下所示:
<div *ngFor="let category of categories">
<input type="checkbox" value={{category.id}}/> {{category.name}}
</div>
我的错误:
Cannot find a differ supporting object '[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]' of type 'string'. NgFor only supports binding to Iterables such as Arrays.
我去另一个视图很好,但是 IDK 为什么我的错误,如果我尝试:JSON.parse 错误更改为
Unexpected token o in JSON at position 1
Error: Error in :0:0 caused by: Unexpected token o in JSON at position 1
我一直在阅读有关该错误的信息,看起来我不需要解析,所以我很困惑。
帮助,谢谢!
更新
这是转到另一个视图之前的数据。
【问题讨论】:
-
您的
categories不是数组。它是一个对象。 -
你能分享你正在传递的数据吗? PL。提出问题,不要发表评论
-
@Smit 在那里
-
你可以先对你的对象进行字符串化,然后发送给参数。然后一旦你收到它......解析它。
标签: json angular angular2-routing