user2024080
user2024080

Reputation: 5101

`ngClass` directive apply class as `object` instead of `class` value

I am applying the class name as follows:

<tr *ngIf="crud.isCreate" [ngClass]="{'create' : curd?.isCreate}">

but I am not class name added with it. in html it shows like:

<tr _ngcontent-yql-c9="" ng-reflect-ng-class="[object Object]"> - what is wrong here?

*ngIf="crud.isCreate" - condition works properly.

any one help me to understand?

Upvotes: 1

Views: 3111

Answers (2)

Yash Rami
Yash Rami

Reputation: 2327

you can try like this. I'm considering no typo in your code.

<tr *ngIf="crud.isCreate" [ngClass]="curd?.isCreate ? 'create' : ''">

I hope it helps you out

Upvotes: 0

abd995
abd995

Reputation: 1839

You have a typo there. curd should be crud

<tr *ngIf="crud.isCreate" [ngClass]="{'create' : crud?.isCreate}">

Upvotes: 3

Related Questions