Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullInjectorError: No provider for NgxMaskPipe! #1072

Closed
cmalard opened this issue Feb 21, 2023 · 2 comments
Closed

NullInjectorError: No provider for NgxMaskPipe! #1072

cmalard opened this issue Feb 21, 2023 · 2 comments

Comments

@cmalard
Copy link

cmalard commented Feb 21, 2023

🐞 bug report

Is this a regression?

Description

Hello there 🙋
Following the README, I can't make ngxMaskPipe works

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-13-qga3fs?file=src%2Fapp%2Fapp.component.ts

🔥 Exception or Error

Error: R3InjectorError(AppModule)[NgxMaskPipe -> NgxMaskPipe -> NgxMaskPipe]:
NullInjectorError: No provider for NgxMaskPipe!

🌍 Your Environment

Angular Version:

"@angular/...": "15.1.5",
"ngx-mask": "15.0.2",

Anything else relevant?

I managed to make it work with

providers: [{ provide: NgxMaskPipe, useClass: NgxMaskPipe }],

but feels like a workaround :-)

@dougmbarcellos
Copy link

Try:

      imports: [
        ...,
        NgxMaskPipe,
      ],
      providers: [..., NgxMaskPipe, provideEnvironmentNgxMask()],

@NepipenkoIgor
Copy link
Collaborator

@cmalard At first personally i don't like using pipe as a service. Pipe it is special things in Angular that we need to use in template . You could easily use NgxMaskApplierService for your purpose .

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, FormsModule],
  providers: [
    provideNgxMask(),
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

And then

  constructor(private readonly maskService: NgxMaskApplierService) {
    this.ibanMasked = this.maskService.applyMask(this.IBAN, this.IBAN_MASK);
  }

I just forked your example please look
https://stackblitz.com/edit/angular-13-vtfzel?file=src/app/app.component.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants