简体   繁体   中英

NgFor only supports binding to Iterables such as Arrays in Ionic3

I wish to convert an Ionic's storage object to an array to be readable in a ion view. I get this error : NgFor only supports binding to Iterables such as Arrays. How to convert an object to an array ? Do i have to forEach storage the push the data to an array ? This is the object : 在此处输入图片说明 Regards Frank

You can use ES6's Object.values to get an array of values:

 var obj = { "1": { prop: "xxx" }, "2": { prop: "yyy" }, "3": { prop: "zzz" } } var arr = Object.values(obj); console.log(arr);

I try an approch to get an array of the storage ionic object like this:

this.storage.forEach((value: string, key: string, index: number) => {
                        //console.log(key);
                        console.log('value',value);
                        });

It returns an array of the object but with additional values ! Strange ..... Solution from here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM