Untitled conversation
- 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", "_rev": "1-3a5afadc2e2b7e2f7afcb8523a388f08" } } how can dispal all recored of cont_act using angular ts from rxdb
- Assistant
Assuming that you have set up an RxDB instance and have already fetched the desired document containing the
cont_actarray, you can iterate over the array and display its contents using Angular'sngFordirective in your template file.Here's an example TypeScript code snippet that fetches the document and stores it in a variable called
doc, which is then used to display thecont_actarray in the template:import { Component } from '@angular/core'; import { RxDatabase, RxDocument } from 'rxdb'; interface YourDocType { color: string; hp: number; snrcn: string; cont_act: { emil: string; }[]; // add any other properties here if needed } @Component({ selector: 'app-display-cont-act', templateUrl: './display-cont-act.component.html' }) export class DisplayContActComponent { doc: RxDocument<YourDocType>; constructor(private db: RxDatabase) {} ngOnInit() { this.db.collection<YourDocType>('your-collection-name').findOne('test') .then((doc) => this.doc = doc); } }And here's an example template file that displays the
cont_actarray usingngFor:<ul> <li *ngFor="let contact of doc.cont_act"> {{contact.emil}} </li> </ul>This will render a bulleted list of email addresses from the
cont_actarray. You can modify the template to display other properties as needed. - User
<ng-container *ngFor="let hero of heroes$ | async as heroes; index as i; let last = last"> display cont_act
- Assistant
Assuming that you have already fetched the desired document containing the
cont_actarray and stored it in a variable calleddoc, you can iterate over thecont_actarray and display its contents using Angular'sngFordirective.Here's an example TypeScript code snippet that gets your document data using RxDB, selects the
cont_actarray, maps it to an array of email addresses only, and saves it in a variable calledcontactsthat can be used in the template:import { Component } from '@angular/core'; import { RxDatabase, RxDocument } from 'rxdb'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; interface YourDocType { color: string; hp: number; snrcn: string; cont_act: { emil: string; }[]; // add any other properties here if needed } @Component({ selector: 'app-display-cont-act', templateUrl: './display-cont-act.component.html' }) export class DisplayContActComponent { doc$: Observable<RxDocument<YourDocType>>; contacts$: Observable<string[]>; constructor(private db: RxDatabase) {} ngOnInit() { this.doc$ = this.db.collection<YourDocType>('your-collection-name').findOne('test'); this.contacts$ = this.doc$.pipe( map(doc => doc.cont_act.map(contact => contact.emil)) ); } }And here's an example template file that displays the
cont_actarray usingngFor:<ul> <li *ngFor="let contact of contacts$ | async; index as i; let last = last"> {{contact}}{{last ? '' : ','}} </li> </ul>This will render a comma-separated list of email addresses from the
cont_actarray. You can modify the template to display thecont_actarray properties as needed.