@mattlewis92/angular2-text-mask
@mattlewis92/angular2-text-mask
npm i @mattlewis92/angular2-text-mask
@mattlewis92/angular2-text-mask

@mattlewis92/angular2-text-mask

Input mask for React, Angular, Ember, Vue, & plain JavaScript

by text-mask

10.0.0 (see all)License:UnlicenseTypeScript:Not Found
npm i @mattlewis92/angular2-text-mask
Readme

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 directive.

📍 For more information about the values that the textMask object accepts, see this page.

Other use-cases

Unmasking the value that is stored in the model

Text Mask does not provide an option to unmask the model before storing it. You can sanitize the model on your side. See here for details.

change doesn't work

change on an input field will not work if [text-mask] is present. You can use (ngModelChange) instead. For more information, see this page.

Example

To see an example of the code running, follow these steps:

  1. Clone the repo, git clone git@github.com:text-mask/text-mask.git
  2. cd text-mask
  3. cd angular2
  4. npm install
  5. npm start
  6. Open http://localhost:3000

The code of the example is in angular2/example.

Ionic 2

Unfortunately, we are unable to support Ionic 2 ion-input at this point as it overrides the ControlValueAccessor that Text Mask requires to perform its job.

Downloads/wk

1

GitHub Stars

8.2K

LAST COMMIT

2yrs ago

MAINTAINERS

1

CONTRIBUTORS

66

OPEN ISSUES

260

OPEN PRs

54
VersionTagPublished
10.0.0
latest
4yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate