From 0fe619fb469fa7d5f6e809241a500844a3297aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fatay=20=C3=87ivici?= Date: Thu, 10 Aug 2017 15:42:29 +0300 Subject: [PATCH] Fixed #2632 --- src/app/components/inputmask/inputmask.ts | 28 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/app/components/inputmask/inputmask.ts b/src/app/components/inputmask/inputmask.ts index cd8290c174b..8993fac911a 100644 --- a/src/app/components/inputmask/inputmask.ts +++ b/src/app/components/inputmask/inputmask.ts @@ -50,9 +50,7 @@ export const INPUTMASK_VALUE_ACCESSOR: any = { providers: [INPUTMASK_VALUE_ACCESSOR,DomHandler] }) export class InputMask implements OnInit,OnDestroy,ControlValueAccessor { - - @Input() mask: string; - + @Input() type: string = 'text'; @Input() slotChar: string = '_'; @@ -91,6 +89,8 @@ export class InputMask implements OnInit,OnDestroy,ControlValueAccessor { value: any; + _mask: string; + onModelChange: Function = () => {}; onModelTouched: Function = () => {}; @@ -128,6 +128,25 @@ export class InputMask implements OnInit,OnDestroy,ControlValueAccessor { constructor(public el: ElementRef, public domHandler: DomHandler) {} ngOnInit() { + let ua = this.domHandler.getUserAgent(); + this.androidChrome = /chrome/i.test(ua) && /android/i.test(ua); + + this.initMask(); + } + + @Input() get mask(): string { + return this._mask; + } + + set mask(val:string) { + this._mask = val; + + this.initMask(); + this.writeValue(''); + this.onModelChange(this.value); + } + + initMask() { this.tests = []; this.partialPosition = this.mask.length; this.len = this.mask.length; @@ -138,9 +157,6 @@ export class InputMask implements OnInit,OnDestroy,ControlValueAccessor { '*': '[A-Za-z0-9]' }; - let ua = this.domHandler.getUserAgent(); - this.androidChrome = /chrome/i.test(ua) && /android/i.test(ua); - let maskTokens = this.mask.split(''); for(let i = 0; i < maskTokens.length; i++) { let c = maskTokens[i];