Use Elvis Perator in conjunction with ngIf

Asked

Viewed 76 times

0

Hello, I have the following element:

Product.description_b2w.description

Sometimes that description does not exist in this product, so when I try to apply ngModel and *ngIf in it I get:

Cannot read Property 'Description' of null

This is my template:

<textarea *ngIf="produto.descricao_b2w.descricao !== null" rows="4" [(ngModel)]="produto.descricao_b2w.descricao" readonly type="text" name="descricaob2w" id="descricaob2w{{i}}" class="form-control">

I tried Elvis in a few different ways, but none managed to reach my goal, ngModel can’t find the description because it doesn’t really exist in the object, it only exists sometimes.

1 answer

1


The previous object may be null, try this way.

<textarea *ngIf="produto.descricao_b2w !== null" rows="4" [(ngModel)]="produto.descricao_b2w.descricao" readonly type="text" name="descricaob2w" id="descricaob2w{{i}}" class="form-control">

Browser other questions tagged

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