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

298
Visualizações
Angular: Component scss styles not applied to tags supplied to [innerHTML] of div?

I've got a MatDialog which is supplied with an HTML string by its parent when it's constructed. The HTML string is the source of a named div's content, and contains <table> tags embedded within the html, but for some reason the table style defined in the dialog's scss file isn't applied to the string I specify as [innerHTML] , although it works fine for <table> tags hard-coded directly into the html file.

Is there some way I can get the dialog to render the innerHTML with styles contained in the styles template for the dialog componenet?

    export class DialogAgreementViewer implements AfterViewInit {
      constructor(public dialogRef:
        MatDialogRef<DialogAgreementViewer>, @Inject
        (MAT_DIALOG_DATA) public data: string, protected _sanitizer : DomSanitizer){
          this.agreementText = this._sanitizer.bypassSecurityTrustHtml(data);
        }
      public agreementText : SafeHtml;
      @ViewChild('agreementText') agreementTextCtl : ElementRef;
    }

HTML:

    <p>Agreement Template</p>
    <table>.          <-- Defined table styles are applied to this table.
        <tbody>
            <tr><td>Title</td><td>Name of Work</td></tr>
        </tbody>
    </table>
    
    <div [innerHTML]='agreementText'></div> <-- Table styles not applied here.

SCSS:

    table, td {
        border: 1px solid black;
       
    }
    table {
        border-collapse: collapse;
        width: 75%
    }
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Import ViewEncapsulation along with Component:

import { Component, ViewEncapsulation } from '@angular/core';

and set encapsulation for the component in the decorator, along with selector, template, css styles etc:

encapsulation: ViewEncapsulation.None

For example:

@Component({
  selector: 'your-app',
  templateUrl: './your.component.html',
  styleUrls: ['./your.component.css'],
  encapsulation: ViewEncapsulation.None, // <---------
})
about 4 years ago · Juan Pablo Isaza Relatório

0

You should disable encapsulation for that component. You can do it like this:

import { Component, ViewEncapsulation } from '@angular/core';
...
@Component({
  ...
  encapsulation: ViewEncapsulation.None,
})
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