Data from an Array (Angular)

Asked

Viewed 49 times

0

I’m trying to use data from an Array to place on an object.. for example:

lembreteSistemaList = LembreteSistema [] = [];
lembreteSistema = LembreteSistema = new LembreteSistema();

recuperarLembrete () {
...
.subscribe((lembreteSistemaVar: Array <LembreteSistema> ) => {
this.lembreteSistemaList = lembreteSistemaVar
}

wanna get this reminderSistemaList and place inside the reminderSystem so that in html you can use it like this

    <textarea class="form-control" id="message-text"> {{ lembreteSistema.nome }} </textarea>

Obs: I’ve tried *ngFor in html but it didn’t work..

1 answer

2


Dude is because this reminderSistemaList is an array of objects in this case you could do something like this.

<textarea class="form-control" id="message-text" *ngFor="let lembrete of lembreteSistemaList"> {{ lembrete.nome }} </textarea>

Because then you will be accessing the object inside the array or could do using the pipe json 'will get very ugly but would solve your case'

<textarea class="form-control" id="message-text"> {{ lembreteSistemaList | json }} </textarea>

Or to make it easier I’d still use it like this

lembreteSistemaList$: Observable<LembreteSistema[]>;

    <ng-container *ngIf="lembreteSistemaList$ | async as lembreteSistemaList">
        <textarea class="form-control" id="message-text" *ngFor="let lembrete of lembreteSistemaList"> {{ lembrete.nome }} </textarea>
    </ng-container>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.