Skip to content

Instantly share code, notes, and snippets.

@valterbarros
Created August 26, 2019 14:21
Show Gist options
  • Save valterbarros/e4a2d15543f7e3eeb3e9d7758ef1fedc to your computer and use it in GitHub Desktop.
Save valterbarros/e4a2d15543f7e3eeb3e9d7758ef1fedc to your computer and use it in GitHub Desktop.
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