Ngx-mask: Expose a service for applying mask in typescript

Created on 7 Mar 2019  路  6Comments  路  Source: JsDaddy/ngx-mask

Please advise how to apply a mask in typescript code.

Correct me if I am wrong, but I do not see any exposed service that I can use to do this. MaskService cannot be injected into a service, because it requires an ElementRef, which throws an error on injection NullInjectorError: No provider for ElementRef!.

There is another service MaskApplierService, but it is not exposed in the public_api. In any case there is no documentation on the difference between these two services.

If it is not currently possible to apply the mask outside of an Angular template, please add as a feature the correct service to use, or a utility class that can be imported. The use case is for data export.

P2 enhancement question

Most helpful comment

@kevinrstone @douggass we fixed this , you can use in mask 7.9.8 version
For using you should use MaskApplierService
Example:

constructor(private maskService: MaskApplierService) {} 
  exportData() {
    const phoneNumber: string = this.maskService.applyMask('12345678901', '000-0000-00-00');
}

All 6 comments

@kevinrstone could you provide an example ?

How do I do something like this? It is not currently possible to import MaskService. Each item in our database may have a different mask, depending on region. It is not desirable to attempt to reproduce the code for applying and displaying a mask.

```@Injectable()
export class ExportDataService {
constructor(
private maskService: MaskService
) {}

exportData(item: any) {

    let phoneNumber: string = maskService.applyMask(item.rawPhoneNumber, item.maskString);
    // export phone number to CSV, Email, other service, etc
}

}
```

solution? I have same problem.

@kevinrstone @douggass we fixed this , you can use in mask 7.9.8 version
For using you should use MaskApplierService
Example:

constructor(private maskService: MaskApplierService) {} 
  exportData() {
    const phoneNumber: string = this.maskService.applyMask('12345678901', '000-0000-00-00');
}

@kevinrstone @douggass we fixed this , you can use in mask 7.9.8 version
For using you should use MaskApplierService
Example:

constructor(private maskService: MaskApplierService) {} 
  exportData() {
    const phoneNumber: string = this.maskService.applyMask('12345678901', '000-0000-00-00');
}

work when I import 'ea':
import { 傻a } from 'ngx-mask';
...
constructor(private maskApplierService: 傻a) {
console.log(maskApplierService.applyMask('5555', '00-00'));
}
...

thank you

Why is nfx-mask.d.ts like this?
export { MaskApplierService as 傻a } from './app/ngx-mask/mask-applier.service';

I'm on 7.9.10.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

humpedli picture humpedli  路  3Comments

cabbott65 picture cabbott65  路  4Comments

prosto-artem picture prosto-artem  路  4Comments

salazarr-js picture salazarr-js  路  3Comments

TimWarp picture TimWarp  路  4Comments