Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda