Ngx-mask: Add ability to use MaskPipe/MaskService inside component

Created on 23 Aug 2018  路  5Comments  路  Source: JsDaddy/ngx-mask

Currently, there is no ability to inject MaskPipe/MaskService into component constructor to apply mask in TypeScript.

enhancement

Most helpful comment

@Alexandr98, so I have installed the 6.2.8 version and here what I have:

ngx-mask.d.ts (file)
image

Seems like default d.ts generator renamed exports.

Also, MaskPipe has a dependency on MaskApplierService, so it makes things complicated where they supposed to be simple:

Example 1:
I would like to apply mask inside my component

Solution 1:

  1. Inject MaskApplierService into component constructor
  2. create instance of MaskPipe and pass instance of MaskApplierService into constructor parameter
  3. use MaskPipe.transform method

Solution 2:

  1. Register MaskPipe as provider in my module like:
    { provide: MaskPipe, useClass: MaskPipe }
  2. Inject MaskPipe into component constructor
  3. use MaskPipe.transform method

Proposed Solution
Can we make MaskPipe constructor parameterless, so we can use it as pure pipe?
If MaskApplierService is used just as way to avoid code duplication, it could be used
as internal class without need to be exported and registered as Angular Injectable.

This will allow create instances of MaskPipe without and additional steps provided
and it will behave as pure stateless function.

All 5 comments

@nazar-kuzo We released new version with that property, try 6.2.8.

@Alexandr98, so I have installed the 6.2.8 version and here what I have:

ngx-mask.d.ts (file)
image

Seems like default d.ts generator renamed exports.

Also, MaskPipe has a dependency on MaskApplierService, so it makes things complicated where they supposed to be simple:

Example 1:
I would like to apply mask inside my component

Solution 1:

  1. Inject MaskApplierService into component constructor
  2. create instance of MaskPipe and pass instance of MaskApplierService into constructor parameter
  3. use MaskPipe.transform method

Solution 2:

  1. Register MaskPipe as provider in my module like:
    { provide: MaskPipe, useClass: MaskPipe }
  2. Inject MaskPipe into component constructor
  3. use MaskPipe.transform method

Proposed Solution
Can we make MaskPipe constructor parameterless, so we can use it as pure pipe?
If MaskApplierService is used just as way to avoid code duplication, it could be used
as internal class without need to be exported and registered as Angular Injectable.

This will allow create instances of MaskPipe without and additional steps provided
and it will behave as pure stateless function.

Is this possible already? to use in component?

@lixaotec
It is 馃槉

Thanks dude. Just managed to it. Passed maskpipe in a constructor . Worked very well, im building a generic pipe for my datatable

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raisiqueira picture raisiqueira  路  3Comments

sbeka picture sbeka  路  3Comments

eehaddad picture eehaddad  路  3Comments

v1d3rm3 picture v1d3rm3  路  4Comments

tanjuyayak picture tanjuyayak  路  3Comments