0
点赞
收藏
分享

微信扫一扫

Angular4_格式化手机号,银行卡号,地址,数字


Installation and usage

  • React
  • Angular 2 or Angular 1
  • Ember
  • Vue
  • Vanilla JS


Angular 2 Input Mask

Getting started

First, install it.

npm i angular2-text-mask --save

Then, import it into your @NgModule:

import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { TextMaskModule } from 'angular2-text-mask';

@NgModule({
  imports: [
    FormsModule,
    TextMaskModule
  ],
  declarations: []
})
export class MyModule {}

Then, use it in your component:

@Component({
  selector: 'app',
  template: `
    <input [textMask]="{mask: mask}" [(ngModel)]="myModel" type="text"/>
  `
})
export class AppComponent {
  public myModel = ''
  public mask = ['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]
}

Documentation

As you can see in the code above, you are passing an object to the textMask

举报

相关推荐

0 条评论