且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找不到其他支持对象Error Angular2

更新时间:2023-11-19 23:23:04

实际上,当您单击从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 .