3

I want to implement input mask in my angular 7 project. I need to know the steps to be followed.

I am trying to use this plugin.

I following the following steps.
Step 1: npm install inputmask --save
Step 2: Imported in my app rounting as import Inputmask from "inputmask";
And in declaration declarations: [Inputmask ]

Step 3: In my component.html
<input data-inputmask="'mask': '[9-]AAA-999'" im-insert="true">

I am getting following issues:
Uncaught Error: Unexpected value 'Inputmask' imported by the module 'AppRoutingModule'. Please add a @NgModule annotation.

How can fix it? Or can i get example code or link.

2
  • You werent supposed to add in AppModule instead of AppRoutingModule ? Commented Apr 12, 2019 at 13:10
  • The import Inputmask from "inputmask" is only used to import an ES module, not an Angular module. The imported ES module cannot be declared as a angular component/directive. Importing the ES module gives you access to the Inputmask for use in your typescript code, but it doesn't connect it to the angular template. Commented Apr 12, 2019 at 13:21

1 Answer 1

5

I finally found out how to fix it.

  1. Install Jquery and inputMask

    npm install jquery --save npm install inputmask --save

  2. Add jquery and mask js to angular-cli.json

    scripts: [ "../node_modules/jquery/dist/jquery.min.js", "../node_modules/inputmask/dist/jquery.inputmask.bundle.js" ]

  3. Import in your component

    import * as Inputmask from "inputmask"

  4. Call it in NgOnInit

    ngOnInit() { Inputmask().mask(document.querySelectorAll("input")); }

  5. Add mask into input tag

    <input data-inputmask="'mask': '99-9999999'" />

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.