Created
August 26, 2019 14:21
-
-
Save valterbarros/e4a2d15543f7e3eeb3e9d7758ef1fedc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, ElementRef, OnDestroy } from '@angular/core'; | |
import * as textMask from 'vanilla-text-mask/dist/vanillaTextMask.js'; | |
@Directive({ | |
selector: '[maskCurrencyDirective]' | |
}) | |
export class MaskCurrencyDirective implements OnDestroy { | |
mask = ['$', /\d+/] | |
maskedInputController; | |
constructor(private element: ElementRef) { | |
this.maskedInputController = textMask.maskInput({ | |
inputElement: this.element.nativeElement, | |
mask: this.mask | |
}); | |
} | |
ngOnDestroy() { | |
this.maskedInputController.destroy(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment