The structure is as follows: A book consists of multiple fragments, each containing chapters that further include verses.
For fragments, the property of interest is the title. For verses, the properties of interest are verse number and verse text. (The data related to chapters is not relevant to the user).
Below are the models for the respective entities:
Fragments.ts:
import {Deserializable} from './deserializable';
import { Chapter } from './chapter';
import { Verse } from './verse';
export class Fragment implements Deserializable {
public id?: number;
public url?: string;
public surtitle?: string;
public title_string?: string;
public title_format?: number;
public verses?: Verse;
public chapter_id?: Chapter;
deserialize(input: any): this {
Object.assign(this, input);
return this;
}
chapters.ts:
import {Deserializable} from './deserializable';
import { Livre } from './livre';
export class Chapter implements Deserializable {
public id?: number;
public url?: string;
public number?: number;
public book_id?: Livre;
deserialize(input: any): this {
Object.assign(this, input);
return this;
}
}
verse.ts:
import {Deserializable} from './deserializable';
import { Fragment } from './fragment';
export class Verse implements Deserializable {
public id?: number;
public url?: string;
public number?: number;
public text?: string;
public optional_indication?: number;
public fragment_id?: Fragment;
deserialize(input: any): this {
Object.assign(this, input);
return this;
}
}
The main objective is to present the book's content to the user on a web page: beginning with the title of a fragment, followed by its verses, then moving on to the next fragment and its verses, and so forth.
Currently, the code in the "livre-detail.component.ts" component successfully retrieves the entire book content, including fragments and nested data down to the verse text, logging the JSON data correctly in the console or browser when using the template snippet below:
<div *ngFor= 'let fragment of fragments'>
{{ fragment | json}}
</div>
In the template, looping through the fragments via *ngFor directive effectively displays the title of each fragment ("fragment.title_string").
However, I'm facing challenges when attempting a nested loop to display the text of each verse within each fragment.
I've experimented with various approaches:
Using Angular's keyvalue property as recommended in Angular2 - *ngFor / loop through json object with array
Creating a variable for the verses in the component file utilizing a nested map, as proposed in Angular2 nested *ngFor. The concept is similar to the one discussed at Angular2 nested *ngFor (refer to the code under Alternative 2)
Here is the current code implementation:
livre-detail-component.ts:
// Component code here
livre-detail-component.html:
// Template code here
The error messages and issues encountered are detailed within the code comments above. Any assistance would be highly appreciated.