找不到其他支持对象Error Angular2 [英] Cannot find a differ supporting object Error Angular2
问题描述
尝试使用 * ngIf
从本地存储中获取值(对象数组)并显示,但是角度抛出错误为找不到其他支持对象
.这是Plnkr投掷错误
Trying to get Values (Array of Objects) from Local Storage and Displaying using *ngIf
but angular throws error of Cannot find a differ supporting object
.
here is Plnkr throwing error
http://plnkr.co/edit/qgrOmRlUcAZq1spGALEa?p=preview
<template ngFor #permissionvar [ngForOf]="LocalStorageData">
<li class="dropdown-submenu" *ngIf="permissionvar.root_permission_name == 'School Setting'">
<a (click)="Schoolsettings()">
<i class="fa fa-gears"></i>
<span>School Settings</span>
</a>
<ul class="dropdown-menu">
<li>ABC</li>
</ul>
</li>
</template>
似乎无法找出 permissionvar.root_permission_name
,我不知道为什么?
seems unable to find out permissionvar.root_permission_name
, i don't know why ?
推荐答案
实际上,当您单击从LocalStorage获取"按钮时,您是从存储中获取字符串而不是数组.因此,您需要先解析它,然后才能在ngFor中使用它:
In fact, when you click on the "Get from LocalStorage" button, you get a string from the storage and not an array. So you need to parse it before trying to use it in ngFor:
getData(){
this.LocalStorageData = JSON.parse(localStorage.getItem("DEMO data"));
}
请参阅以下示例: http://plnkr.co/edit/aumB4mMNVlV9TK5KDjoF?p=preview .
这篇关于找不到其他支持对象Error Angular2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!