Angular2, inputmask ngModel binding

391 views
Skip to first unread message

Константин Забродин

unread,
Jul 5, 2016, 11:52:54 AM7/5/16
to AngularJS

Hello everyone, I have some problem with ng2 ang inputmask. For example I have had this code
component.html

<div class="form-group col-sm-7"> 
 <label class="control-label" for="sender-phone">Phone *</label>  
<input type="text" [(ngModel)]="sender.phone" class="form-control" id="sender-phone" placeholder="Phone">
 </div>
component.ts
ngAfterViewInit() {  
let phoneNumberInput = document.getElementById('sender-phone'); 
 let inputmask = new Inputmask('+7(999)999-99-99');  
inputmask.mask(element);  
}

Inputmask is working good. But my [(ngModel)] didn't work. Anyone know how I can resolve my issue ?

My code for example http://plnkr.co/edit/F3pob7hH2ZrJv0MDNa9x?p=preview

Sander Elias

unread,
Jul 8, 2016, 8:42:52 AM7/8/16
to AngularJS
Hi Константин 

The problem is that your JQ plugin is not fireing the needed events. It eats the change and input events. It does not have very well.
There is a eay way around, just leverage the power of NG2 and attached the change detection to the keyup event.
Here is a sample on how to do that/

Regards
Sander

Dumitru Fostic

unread,
Jan 17, 2017, 11:38:28 AM1/17/17
to Angular
Hi All,

I am trying to figure out input mask for already couple of days, and nothing is working. Even simple examples do not.
Here you are telling that at least mask is working. I have tried your code but InputMask class is not recognized, and i don't see it in imports.

Can you help me please?
Please, write anything you put in package.json, systemjs.config.js, app.module.ts, etc.

Thank you in advance!
Reply all
Reply to author
Forward
0 new messages