my textarea does not want to show content with you in my ngmodel

Asked

Viewed 41 times

0

I have an object that I receive from a request, I am trying to put the value of this attribute in the template but it does not appear in the textarea.

for(let i=0;i<this.produtosConfirmadosAnuncio.length;i++){
  if(this.produtosConfirmadosAnuncio[i].descricao_b2w == null){
    console.log('entrou no nulo')
    this.produtosConfirmadosAnuncio[i].descricao_b2w = {descricao: null, id: null};
  }
}

In this function I check if the descricao_b2w is null, if it is I create keys and values with null value (I did this because I was giving error in the template when the descricao_b2w object was null, so I could not find the Description key, claimed that it was Undefined).


My template:

<div *ngFor="let produto of produtosConfirmadosAnuncio; let i = index" class="col-xl-4">

    <textarea class="form-control" 
    name="message"
    rows="3"
    [(ngModel)]="produto.descricao_b2w.descricao"
    #message='ngModel'
    >{{produto.descricao_b2w.descricao}}</textarea>

I also tried to:

   <textarea class="form-control" 
    name="message"
    rows="3"
    [(ngModel)]="produto.descricao_b2w.descricao"
    #message='ngModel'
    >{{produto.descricao_b2w.descricao}}</textarea>

and also tried to:

<textarea class="form-control" 
rows="3"
[(ngModel)]="produto.descricao_b2w.descricao"
></textarea>

2 answers

1

Try this way

[ngModel]="produto?.descricao_b2w?.descricao" (ngModelChange)="produto.descricao_b2w.descricao = $event"
  • Parser Error: The '?. ' Operator cannot be used in the assignment at at

  • I think you need to put in the previous one too, take a look now

  • 1

    made the same mistake, but I got it here, thank you

  • changed again

0


For me it worked that way:

 <textarea class="form-control" rows="3" #textbox (change)="produto.descricao_b2w.descricao = textbox.value">{{ produto.descricao_b2w.descricao }}</textarea>

Browser other questions tagged

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