Hello. ngClass and ngStyle are not working when used with custom breakpoints after upgrading angular version from 7 to 8.
ngClass and ngStyle should be working ( when used with custom breakpoints ) as they are working in angular version 7
an error is thrown when trying to use one of these directives with a custom defined breakpoint
error message : (No provider for NgClassImpl!)
minimal StackBlitz version:
https://stackblitz.com/github/Saied-Za/Angular-FlexLayout
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._
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
NgClassandNgStyle, 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: