ngx-mask icon indicating copy to clipboard operation
ngx-mask copied to clipboard

Add ability to use MaskPipe/MaskService inside component

Open nazar-kuzo opened this issue 8 years ago • 7 comments

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

nazar-kuzo avatar Aug 23 '18 15:08 nazar-kuzo

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

pryimakalex avatar Oct 01 '18 13:10 pryimakalex

@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.

nazar-kuzo avatar Oct 01 '18 15:10 nazar-kuzo

Is this possible already? to use in component?

lixaotec avatar Aug 28 '20 23:08 lixaotec

@lixaotec It is 😊

nazar-kuzo avatar Aug 28 '20 23:08 nazar-kuzo

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

lixaotec avatar Aug 29 '20 02:08 lixaotec

@lixaotec Is there an example you could provide with the parameters you passed to the maskPipe please? Thanks a lot

guidogr95 avatar May 12 '22 17:05 guidogr95

ngx-mask works with Angular, and Angular - Ionic!

constructor(private _formBuilder: FormBuilder, private maskPipe: MaskPipe) {}

updateWithMask(event) { this.myForm.controls.cpf.setValue(this.maskPipe.transform(event.currentTarget.value, '000.000.000-00')); }

Ionic CLI : 6.19.1 Ionic Framework : @ionic/angular 6.1.8 @angular-devkit/build-angular : 13.2.6 @angular-devkit/schematics : 13.2.6 @angular/cli : 13.2.6 @ionic/angular-toolkit : 6.1.0

Reference: http://dev.diogomachado.com/ionic-input-with-mask/

DsiKorp avatar Jun 02 '22 15:06 DsiKorp