Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

309
Visualizações
Change Multiple CSS property from multiple CSS class dynamically in Angular

In angular, we can easily change the property of a CSS class dynamically, like if I have a class

.my-class {
  background: url('..')
}

and if I used my-class as

<div class="my-class">
  ------
</div>

now, we can change the image effectively by using

[style.background]="url(..)"

like

<div class="my-class" [style.background]="getImageUrl()">
    ----
</div>

Now, can anyone tell me, is there any solutions if there's have multiple css-class and there I have to change background url all of them, how can I do it?

Like my CSS classes are

.my-class-one {
  background: url('..')
}

.my-class-two {
  background: url('..')
}

.my-class-three {
  background: url('..')
}

and HTML code is

<div class="my-class-one my-class-two my-class-three">
  ----
</div>

There I need to change all background image URL by calling angular methods

getImageUrlOne()
getImageUrlTwo()
getImageUrlThree()
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

ngClass can be used in html

[ngClass]="{'my-class-one': getImageUrlOne(), 'my-class-two': false, 'my-class-three': false}"

JS

getImageUrlOne(){
   //.... logic to decide my-class-one should be used or not
   return true;
}
about 4 years ago · Juan Pablo Isaza Relatório

0

You can set different-different flag variable in each function and when function call then set one flag true. set ngclass as below:

<div [ngClass]="{'my-class-one': getImageUrlOne(), 'my-class-two': getImageUrlTwo(), 'my-class-three': getImageUrlThree()}">
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda