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

112
Visualizações
Set custom css variable using hostbinding

I am trying to make a component customizable by having the color as an input. In the end, I want to be able to use the component like this <component-name color="myColor"></component-name>:

To start with, I'm trying to set the css variable using hostbinding, like this:

 @HostBinding('style.--color') myColor: string = '--blue'
:host {
  --blue: #5dbbbb;
  --green: #286e22;

  background-color: var(--color);
}

But the blue never renders. If I inspect the component in chrome, I can see that it has "background-color: --color" When I look at the variable it's defined as --color: --blue

It works fine if I use the hex code directly (@HostBinding('style.--color') myColor: string = '#xxxxxx') instead of the css variable for the color, but I want to avoid that if possible. Any thoughts on what could be wrong? I'm using Angular14.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think you should change your HostBinding code

this

 @HostBinding('style.--color') myColor: string = '--blue'

to

 @HostBinding('style.--color') myColor: string = 'var(--blue)'

And it should work

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