how can get total record of contact from { "id": "test", "rev":…
- User
how can get total record of cont_act from { "_id": "test", "_rev": "1-3a5afadc2e2b7e2f7afcb8523a388f08", "value": { "rev": "1-3a5afadc2e2b7e2f7afcb8523a388f08" }, "key": "test", "doc": { "color": "test", "hp": 100, "snrcn": "test", "cont_act": [ { "emil": "0" }, { "emil": "1" }, { "emil": "2" }, { "emil": "3" }, { "emil": "4" } ], "_id": "test", "_rev": "1-3a5afadc2e2b7e2f7afcb8523a388f08" } } using ngfor <ng-container *ngFor="let hero of heroes$ | async as heroes; index as i; let last = last">
- Assistant
Assuming that the data is retrieved from a database, the total record of cont_act can be obtained by accessing the length property of the cont_act array.
To display the total record of cont_act using ngFor, you can add a variable to hold the length of cont_act in the component, for example:
export class MyComponent { ... contActLength: number; ... constructor(private myService: MyService) {} ... ngOnInit() { this.myService.getData().subscribe(data => { this.contActLength = data.doc.cont_act.length; ... }); } ... }Then, in the HTML template, you can display the total record using interpolation:
Total: {{contActLength}}Note that this assumes that the data is retrieved using an observable (heroes$). If not, you can replace it with the actual data variable.
- User
"_id": "test", "_rev": "1-3a5afadc2e2b7e2f7afcb8523a388f08", "value": { "rev": "1-3a5afadc2e2b7e2f7afcb8523a388f08" }, "key": "test", "doc": { "color": "test", "hp": 100, "snrcn": "test", "cont_act": [ { "emil": "0" }, { "emil": "1" }, { "emil": "2" }, { "emil": "3" }, { "emil": "4" } ], "_id": "test", how can get all element of cont_act angular ngfor {{hero.cont_act}}
- Assistant
To display all the elements of cont_act in Angular using ngFor, you can modify your HTML template like this:
<ul> <li *ngFor="let contact of hero.doc.cont_act">{{ contact.emil }}</li> </ul>This will loop through each element of the cont_act array and display the value of the emil property in a list item. You can update the HTML tags and classes used in the example to suit your needs.