I am starting with the ionic framework and I am stuck in creating and calling an array inside another array.
I have the following code in my books.js
:
.factory('Books', function() {
// books data
var books = [{
id: 0,
title: 'Sample Title',
author: 'Sample Author',
category: 'Horor, Fiction',
cover: '/cover.jpeg',
details: 'some details about the book',
// my first attempt to create an array to store chapters info
chapters: [
{
name: 'Chapter 1',
filename: 'chapter1.html',
},
{
name: 'Chapter 2',
filename: 'Chapter2.html',
}
]
}, {
id: 1,
title: 'Sample Title Two',
author: 'Sample Author two',
category: 'Horor, Fiction',
cover: '/cover.jpeg',
details: 'some details about the book',
// my first attempt to create an array to store chapters info
chapters: [
{
name: 'Chapter 1',
filename: 'chapter1.html',
},
{
name: 'Chapter 2',
filename: 'Chapter2.html',
}
]
},
when accessing data, I use {{book.title}}
and it will output the title of the book. But I am not sure how to return the chapters values since each book has different numbers of chapters.
Perhaps assign a chapter ID for each chapter and call that ID ?
Try this to show it on Angular
<div ng-repeat="book in books">
{{book.title}}
<div ng-repeat="chapter in book.chapters">
{{chapter.name}}
</div>
</div>