text-mask is not working for angular 2

2019-07-23 15:41发布

问题:

Trying to use

https://github.com/text-mask/text-mask/tree/master/addons#createnumbermask

  Uncaught Error: Template parse errors:
    Can't bind to 'textMask' since it isn't a known property of 'input'. ("lex="18" fxFlexOffset="1">


        <input [ERROR ->][textMask]="{mask: numberMask}" type="text" [(ngModel)]="myModel" ): 

I am using

"angular2-text-mask": "^8.0.4",
"text-mask-addons": "^3.7.1",
"text-mask-core": "^5.0.1",

Imported in my Module

imports: [
    BrowserModule,
    FormsModule,
    TextMaskModule
]

trying to use in my component

numberMask = createNumberMask({
    prefix:'',
    suffix:'',
    allowDecimal: true
  })

my html

<md-input-container fxFlex="18" fxFlexOffset="1">
        <span mdPrefix>{{currencySymbol}} &nbsp;</span>
        <input [textMask]="{mask: numberMask}" type="text" [(ngModel)]="myModel" mdInput >
        <md-error>This field is required</md-error>
      </md-input-container>

回答1:

I had to import the Modul in the main Module as well as Specific Module of the application

imports: [
    BrowserModule,
    FormsModule,
    TextMaskModule
]