cesarrew / ng2-currency-mask

A very simple currency mask directive that allows using a number attribute with the ngModel.
MIT License
235 stars 117 forks source link

Not working with Angular Material #168

Closed osvaldoconcepcion closed 2 years ago

osvaldoconcepcion commented 2 years ago

When the currencyMask directive is used with Angular Material:

<mat-form-field>
  <mat-label>Example</mat-label>
  <input currencyMask [(ngModel)]="ngModelExample" [options]="{ prefix: '$ ', thousands: '.', decimal: ',' }">
</mat-form-field>

The following errors are displayed in the console:

core.mjs:6469 ERROR Error: mat-form-field must contain a MatFormFieldControl.
    at getMatFormFieldMissingControlError (form-field.mjs:112)
    at MatFormField._validateControlChild (form-field.mjs:585)
    at MatFormField.ngAfterContentInit (form-field.mjs:386)
    at callHook (core.mjs:2526)
    at callHooks (core.mjs:2495)
    at executeInitAndCheckHooks (core.mjs:2446)
    at refreshView (core.mjs:9510)
    at refreshComponent (core.mjs:10640)
    at refreshChildComponents (core.mjs:9265)
    at refreshView (core.mjs:9519)

And the application crashes.

cesarrew commented 2 years ago

You are using Angular Material in a wrong way. I've updated the project library-test (https://github.com/cesarrew/ng2-currency-mask) with an example using Angular Material.