Why don't add the ngClass the class parameter to the html tag, but the condition is true in Angular template?

why don't we talk
why don't we songs
why don't we merch
why don't we members
why don't we 8 letters
why don't we 2020
why don't we ages
why don't we tour

I have this code in my Angular template:

<div *ngFor="let name of product.names; let index of index" [ngClass]="{'text-muted': index === 0}">
  {{ name.value }}

Then it's generate this HTML code in browser for the first element of names array:

<div _ngcontent-drs-c6="" ng-reflect-ng-class="[object Object]"> Test </div>

Why don't add the class parameter to the div if the condition is true? Where is the mistake in this code?

Try with let i = index"

<div *ngFor="let name of product.names; let i = index" [ngClass]="{'text-muted':  i === 0}">
    {{ name.value }}

Working Demo

Why Don't We, Why Don't We - Unbelievable [Official Music Video] "Unbelievable" out now: https: //wdw.lnk Duration: 3:17 Posted: May 25, 2019 Text us if you need us Merch Events. All content © Why Don't We Privacy Policy | Terms Of Service | AdChoices | Terms Of Service | AdChoices

try this:

[class.text-muted]="index === 0"

Why Don't We - Chills [Official Music Video], Music videos for our songs including Chills, What Am I, Unbelievable, I Don't Belong In This Club, Cold In LA, 8 Letters, Talk, Something Different, and These� Why Don't We (commonly abbreviated WDW) is an American boy band consisting of Zach Herron, Jack Avery, Daniel Seavey, Corbyn Besson, and Jonah Marais.

It happened because let index of index. It is not correct. Correct syntax is let i = index. So try to rewrite like this:

<div *ngFor = "let name of product.names; let i = index" [attr.data-index]="i"
    [ngClass]="{'text-muted': i === 0}"> 

The work stackblitz example can be seen here

Why Don't We - Unbelievable [Official Music Video], 'These Girls' Available NOW: http://whydntwe.co/TheseGirlsYT FOLLOW US https: //twitter.com Duration: 2:50 Posted: Aug 30, 2017 Why Don’t We is a boyband consisting of Daniel Seavey, Zach Herron, Corbyn Besson, Jonah Marais and Jack Avery. Seavey was a contestant on season 14 of American Idol while the other four members

Just try like this

<div *ngFor="let name of product.names; let i = index" [ngClass]="{'text-muted': i === 0}">
  {{ name.value }}

Why Don't We, 4.7m Followers, 64 Following, 743 Posts - See Instagram photos and videos from Why Don't We (@whydontwemusic) Don, abbreviated as D., is an honorific prefix primarily used in Spain and the former Spanish Empire, Italy, Portugal, the Philippines, Latin America, Croatia, and Goa. Don, and dom, is derived from the Latin Dominus: a master of a household, a title with background from the Roman Republic in classical antiquity. With the abbreviated form having emerged as such in the Middle Ages, traditionally it is reserved for Catholic clergy and nobles, in addition to certain educational authorities and pers

These Girls - Why Don't We [Official Music Video], The latest Tweets from Why Don't We (@whydontwemusic). @seaveydaniel • @ jackaverymusic • @corbynbesson • @jonahmarais • @imzachherron. Studio. Daniel Seavey • Zach Herron • Corbyn Besson • Jonah Marais • Jack Avery

Why Don't We (@whydontwemusic) • Instagram photos and videos, Why Don't We. 668K likes. We are Why Don't We • Zach Herron, Daniel Seavey, Jonah Marais, Jack Avery, Corbyn Besson. Of course you don’t, because you aren’t a trained medical professional and you have a life to live. Try and go two minutes, much less two hours, without adjusting it on your face.

Why Don't We, Directed by Kirill Sokolov. With Aleksandr Kuznetsov, Vitaliy Khaev, Evgeniya Kregzhde, Michael Gor. Andrei, a detective and the world's most horrible father, brings together a terrible group of people in his apartment: his resentful actress daughter, an angry thug, and a cheated cop.

  • I want to use the ngClass method, because here will be multiple class based on multiple conditions.
  • Add comments which would explain your answer.
  • I want to use the ngClass method, because here will be multiple class based on multiple conditions.