text-mask不适用于角度2

时间:2017-11-08 19:57:39

标签: angular angular-material text-mask

尝试使用

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" ): 

我正在使用

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

在我的模块中导入

imports: [
    BrowserModule,
    FormsModule,
    TextMaskModule
]

尝试在我的组件中使用

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

我的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 个答案:

答案 0 :(得分:1)

我必须在主模块中导入Modul以及应用程序的特定模块

imports: [
    BrowserModule,
    FormsModule,
    TextMaskModule
]