An Angular 2 wrapper for intl-tel-input library
npm install ng2-tel-inputRun following command to install ng2-tel-input
``sh`
npm install ng2-tel-input intl-tel-input --save
After install, you need to add intlTelInput.css, intlTelInput.min.js, utils.js.
In case of @angular/cli, add 2 files in your angular.json.
For example,
- Include intlTelInput.css in "styles" at your angular.json file :``
"styles": [
...
"node_modules/intl-tel-input/build/css/intlTelInput.css",
...
]
- Include intlTelInput.min.js, utils.js in "scripts" at your angular.json file :``
"scripts": [
...
"node_modules/intl-tel-input/build/js/intlTelInput.min.js"
...
]
Now add Ng2TelInputModule into your AppModule. For example,
`js`
import {Ng2TelInputModule} from 'ng2-tel-input';
Once done, we are ready to use this library.
In order to use this directive, you need to add "ng2TelInput" directive with "[ng2TelInputOptions]" options to your text field. For example,
`html`
ng2TelInput
[ng2TelInputOptions]="{initialCountry: 'in'}"
(hasError)="hasError($event)"
(ng2TelOutput)="getNumber($event)"
(intlTelInputObject)="telInputObject($event)"
(countryChange)="onCountryChange($event)" />
[ng2TelInputOptions]="{initialCountry: 'in', utilsScript: 'node_modules/intl-tel-input/build/js/utils.js'}"
telInputObject(obj) {
console.log(obj);
obj.setCountry('in');
}
``