0
我試圖從另一種觀點認爲獲取數據,如:Angular2無法找到'string'類型的不同支持對象。 NgFor只支持綁定到Iterables如數組
this.paramsSub = this.activatedRoute.params.subscribe(params => this.categories = params['obj']);
this.paramsSub = this.activatedRoute.params.subscribe(params => this.userInfo = params['usr']);
數據以這種方式sended:
this.router.navigate(['/path/obj', {obj: this.categories, usr: this.userInfo}]);
我試圖顯示與* ngFor類別的HTML這樣的:
<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
我一直在閱讀有關該錯誤,它的樣子我不」 t需要解析,所以我非常困惑。
幫助,謝謝!
UPDATE
這是前往其他視圖之前的數據。
你'categories'不是一個數組。它是一個對象。 – Smit
你能分享你傳遞的數據嗎? PL。把這個問題不在評論 – Smit
@Smit那裏是 –