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

311
Visualizações
Conditionally import CSS files in to Angular component

I have different CSS files(red.css,blue.css) in the single Angular Component.How can we import the css file according to the condition. If I mentioned the color as red the red.css file should be imported.

this.activatedRoute.paramMap.subscribe(params=>
{
    let color=params.get('color');
    console.log(color);
})
red.css
.my-container{
    height: 100%;
    background-color: red;
}

blue.css
.my-container{
    height: 100%;
    background-color: blue;
}
<div class="my-container">
    <h1 class="sideheading">URL that entered are processed for Theme Changing of the Page</h1>
</div>

Multiple CSS Files and condition that takes color as input and should apply the css file according to the given color.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

CSS part:

.my-red-container{
    height: 100%;
    background-color: red;
}

.my-blue-container{
    height: 100%;
    background-color: blue;
}

Angular part: let's suppose that You have typescript var named color and Its value is 'blue' or 'red

  <div
    [ngClass]="{'my-red-container': color === 'red', 'my-blue-container' : color === 'blue' }"
    ></div>
over 4 years ago · Santiago Trujillo Relatório

0

CSS Part

.my-red-container{
    height: 100%;
    background-color: red;
}

.my-blue-container{
    height: 100%;
    background-color: blue;
}

Component.html Part

<div [ngClass]="{color === 'red' ? 'my-red-container' : 'my-blue-container'}">
</div>
over 4 years ago · Santiago Trujillo 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