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

149
Visualizações
Bind to unknown property of div in Angular 12

I'm trying to switch the value of an attribute by binding it to a property in my component.

<div class="app-container" [data-theme]="theme">
  <router-outlet></router-outlet>
</div>
import { Component } from '@angular/core';

import { ThemeService } from './common/_services';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  theme = 'dark';

  constructor(private themeService: ThemeService) {
    this.themeService.isDark.subscribe(x => {
      this.theme = x ? 'dark' : 'light';
    });
  }
}

By setting dark or light to the data-theme attribute, different colors are used. So I just need a way of switching the value.

If I try using the code above, I get this:

Error: src/app/app.component.html:1:28 - error NG8002: Can't bind to 'data-theme' since it isn't a known property of 'div'.

Is there any way to bind easily my property to the template? Why am I getting that error?

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

0

I just need to use attribute binding, like so:

[attr.data-theme]="theme"
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