question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ngClass changes incorrectly when printing

See original GitHub issue

Bug Report

On elements with ngClass, the media observers misbehave when printing. For example, if I have…

<p class="text-left" ngClass.lt-sm="text-center">Some text here</p>

…When I press Ctrl + P to print the page, then return, the text is centered (even though the screen size is still 1920px).

What is the expected behavior?

ngClass.lt-sm should be removed when printing is complete

What is the current behavior?

ngClass.lt-sm remains applied

What are the steps to reproduce?

What is the use-case or motivation for changing an existing behavior?

The screen looks incorrect when printing completes

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

I have tested in the latest Angular 8 and 9 releases with FlexLayout 8.0.0-beta.27 and 9.0.0-beta.29 respectively.

Is there anything else we should know?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:22
  • Comments:22 (3 by maintainers)

github_iconTop GitHub Comments

52reactions
alex-vgcommented, Apr 3, 2020

My little dirty hack until this gets resolved…

export class CommonMaterialModule {
  lastValue;

  public constructor (
    m: MediaMarshaller,
  ) {
    // hack until resolve: https://github.com/angular/flex-layout/issues/1201
    // @ts-ignore
    m.subject.subscribe((x) => {
      // @ts-ignore
      if (m.activatedBreakpoints.filter((b) => b.alias === 'print').length === 0) {
        // @ts-ignore
        this.lastValue = [...m.activatedBreakpoints];
      } else {
        // @ts-ignore
        m.activatedBreakpoints = [...this.lastValue];
        // @ts-ignore
        m.hook.collectActivations = () => {};
        // @ts-ignore
        m.hook.deactivations = [...this.lastValue];
      }
    });
  }

}

CommonMaterialModule is my only module that imports (and re-exports) FlexLayoutModule.

7reactions
qliqdevcommented, Jul 15, 2020

I’m using "@angular/flex-layout": "^10.0.0-beta.32" and the problem is still exists in todays.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular ngClass is not updating my classes even though my ...
A workaround of mine is to manipulate a model variable just for the ng-class toggling: 1) Whenever my list is empty, I update...
Read more >
Angular NgFor: Everything you need to know - malcoded
Angular NgFor: Everything you need to know. In this tutorial, we are going to learn about the ngFor directive.
Read more >
Custom Form Validators • Angular - codecraft.tv
A validator in Angular is a function which returns null if a control is valid or an error object if it's invalid. For...
Read more >
Using ngClass for selected value for a background color change
I want to change the background color of value selected. I have tried it using ng class and ngmodel but is not working...
Read more >
Angular ngClass and ngStyle: The Complete Guide
For these type of state styles natively supported by the browser, it's better to use the CSS pseudo classes whenever possible. So for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found