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

138
Visualizações
Angular v8 - Applying a calculated css style to print media

I have an angular component with html which includes the following for positioning labels correctly:

<div *ngFor="let label of labels"
class="text"
[style.left]="calcXPos(label.text.position.x) + 'px'"
[style.top]="calcYPos(label.text.position.y) + 'px'"
...>

This works correctly for setting the x and y positions on the screen.

In the parent component I have 2 buttons for printing:

<button id="printButton1"
    (click)="printChartWithLabels()">
    Print Label from Code
</button>
<button id="printButton2"
    onclick="window.print()">
    Print Chart direct from HTML
</button>

And in the javascript I have the following function

public printChartWithLabels(): void {
  window.print();
}

I have found that when I click printButton2 which has the window.print() command inserted directly in the html, then the [style.left] and [style.top] css values get calculated for the print and the label is in the correct position in the print preview. Debugging shows that calcXPos and calcYPos get called.

However when I use printButton1, then [style.left] and [style.top] css values do not get calculated because calcXPos and calcYPos never get called. This is despite the fact that window.print() is still being used (just being called from the javascript)

Does anyone know why the Angular style calculations only fire for print media if I call window.print() directly from the html?

What is the best way for resolving this to make sure calcXPos and calcYPos are fired even when calling window.print() from the javascript?

about 4 years ago · Juan Pablo Isaza
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