Flex-layout: [solved] Custom breakpoints not working after upgrading to Angular 8

Created on 29 May 2019  路  9Comments  路  Source: angular/flex-layout

Bug Report

Hello. ngClass and ngStyle are not working when used with custom breakpoints after upgrading angular version from 7 to 8.

What is the expected behavior?

ngClass and ngStyle should be working ( when used with custom breakpoints ) as they are working in angular version 7

What is the current behavior?

an error is thrown when trying to use one of these directives with a custom defined breakpoint
error message : (No provider for NgClassImpl!)

What are the steps to reproduce?

minimal StackBlitz version:
https://stackblitz.com/github/Saied-Za/Angular-FlexLayout

P2 docs

Most helpful comment

Ok, I know why this is happening, and it's very much due to a lack of documentation on our part.

When Angular v8 came out, they changed the internal API for NgClass and NgStyle, which Angular Layout extends. We patched this in our own directives, but we couldn't do this for the base directive that's extended for custom breakpoints. We _do_ export a provider for both classes to patch this behavior. To resolve this issue, do the following:

import {Directive} from '@angular/core';
import {LayoutNgClassImplProvider, ClassDirective} from '@angular/flex-layout';

@Directive({selector, inputs, providers: [LayoutNgClassImplProvider]})
export class MyCustomDirective extends ClassDirective {
  ...
}

All 9 comments

Ok, I know why this is happening, and it's very much due to a lack of documentation on our part.

When Angular v8 came out, they changed the internal API for NgClass and NgStyle, which Angular Layout extends. We patched this in our own directives, but we couldn't do this for the base directive that's extended for custom breakpoints. We _do_ export a provider for both classes to patch this behavior. To resolve this issue, do the following:

import {Directive} from '@angular/core';
import {LayoutNgClassImplProvider, ClassDirective} from '@angular/flex-layout';

@Directive({selector, inputs, providers: [LayoutNgClassImplProvider]})
export class MyCustomDirective extends ClassDirective {
  ...
}

Thanks for quick response.

I鈥檓 going to keep this issue open for people with the same problem, at least until we find a way to document this.

Thanks for to keep this issue open!!

I had the same issue but your suggestion helped!

I have kind a same issue in Angular 8.
I use in my custom-component.ts

constructor(@Self ngClass: NgClass) 

as injection to manually set classes on the host component and run into the same runtime error (No provider for NgClassImpl). I implemented a custom directive as you advised, but same error.

What i did wrong? Thanks!

@wlr

providers: [
  {
    provide: 傻NgClassImpl,
    useClass: 傻NgClassR2Impl,
  },
],

and then in component

constructor(@Self() @Optional() ngClassInstance: NgClass, ngClassDelegate: 傻NgClassImpl) {
  this._ngClass = ngClassInstance || new NgClass(ngClassDelegate);
}

This patch has been removed in the recent versions of Angular and Angular Layout, so I'm closing this as not needed anymore.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Pikachews picture Pikachews  路  4Comments

jcoronel94 picture jcoronel94  路  4Comments

spottedmahn picture spottedmahn  路  5Comments

Kizmar picture Kizmar  路  4Comments

Splaktar picture Splaktar  路  4Comments