3
I have a file nvi.json
that is this way:
[
{
"abbrev": "gn",
"book": "Gênesis",
"chapters": [
{
"1": {
"1": "...",
"2": "..."
}
},
{
"2": {
"1": "...",
"2": "..."
}
},
{
"3": {
"1": "...",
"2": "..."
}
}
]
}
]
And I’m accessing it like this:
export class BookPage {
public chapters: Array<string>;
private url: any = "../../assets/nvi.json";
constructor(public navCtrl: NavController, private NavParams: NavParams, public http: Http) {
let id = NavParams.get('id');
this.http.get(this.url).map(res => res.json())
.subscribe(data => {
this.chapters = data[id].chapters[0];
console.log(this.chapters);
});
}
this.chapters
returns the first chapter containing the verses, but I’m not getting a loop
of these verses.
<div *ngFor="let item of chapters">
{{item}}
</div>
Console:
EXCEPTION: Error in ./BookPage class BookPage - inline template:33:5 caused by: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
*ngFor="Let item of Chapters"
– Lucas Bertollo
Thanks for the remark! I posted via mobile and with it many typos.
– Anderson
The Chapters are organized in a way that the angular cannot read ["1":{Object}, "2":{Object}] you need to leave an Objects [{Object},{Object array}]
– Lucas Bertollo
from { "1": { "1": "...", "2": "..." } } would be better to send from backend { "1": [{Chapter:1, .... } , {Chapter:2, .... }] }
– Lucas Bertollo