koque
koque

Reputation: 2256

How do I get ngx-mask npm package for masking phone numbers in Angular to work?

I am trying to use the ngx-mask npm package to work. The instructions are as follow:

Package found here: https://www.npmjs.com/package/ngx-mask

import {NgxMaskModule} from 'ngx-mask'

export const options: Partial<IConfig> | (() => Partial<IConfig>);

@NgModule({
  (...)
  imports: [
    NgxMaskModule.forRoot(options)
  ]
  (...)
})

But I am getting an error on the second line:

export const options: Partial<IConfig> | (() => Partial<IConfig>);

The error says "const options" declaration must be initialized. What do I initialized it to?

Upvotes: 2

Views: 9053

Answers (5)

Navi
Navi

Reputation: 179

I had the same problem and I decided to update the import form in app.module.ts as per the new guidance:

import { NgxMaskDirective, NgxMaskPipe, provideNgxMask } from 'ngx-mask';


 imports: [
    [...]
    NgxMaskDirective,
    NgxMaskPipe
  ],
  
  providers: [
    provideNgxMask()
  ],

Since ng14 and not in ng15 we have changes in API that we described in https://github.com/JsDaddy/ngx-mask

Please check this example:

https://stackblitz.com/edit/angular-13-mc8tvg?file=src%2Fapp%2Fapp.component.ts,src%2Fapp%2Fapp.module.ts,src%2Fapp%2Fapp.component.html

Upvotes: 1

Ioane
Ioane

Reputation: 11

i fixed this problem. install npm i [email protected] this version ;)

Upvotes: 1

Rusell Jane Quitain
Rusell Jane Quitain

Reputation: 151

change

import { NgxMaskModule} from 'ngx-mask';

to

import { NgxMaskModule, IConfig } from 'ngx-mask';

Upvotes: 0

asli
asli

Reputation: 443

you need to initialize to null since it is a interface

import { NgxMaskModule, IConfig } from 'ngx-mask';
export const options: Partial<IConfig> | (() => Partial<IConfig>) = null;

Upvotes: 1

Vin&#237;cius Mussato
Vin&#237;cius Mussato

Reputation: 358

In your app.module.ts try like this:

import { NgxMaskModule, IConfig } from 'ngx-mask';

export let options: Partial | (() => Partial);

@NgModule({
  imports: [
  NgxMaskModule.forRoot(options)],
 }
})

Source

Upvotes: 0

Related Questions