This package is based on https://github.com/webcat12345/ngx-intl-tel-input. But since it's no longer maintained I decided to update it to work with Angular 7. Also phone number validation is working now and there is support for the (Reactive)FormsModule.
- Install ngx-bootstrap
$ ng add ngx-bootstrap
- Install intl-tel-input
$ npm install intl-tel-input --save
- Add intl-tel-input css to angular.json
Look for the
styles
array in your angular.json and add./node_modules/intl-tel-input/build/css/intlTelInput.css
. It should look like this after adding it:
"styles": [
...
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"./node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
"./node_modules/intl-tel-input/build/css/intlTelInput.css",
"src/styles.css"
...
],
- Install google-libphonenumber
$ npm install google-libphonenumber --save
- Install this library
$ npm install angular-intl-tel-input --save
- Add BsDropDownModule and IntlTelInputModule to your angular module file
imports: [
...
BsDropdownModule.forRoot(),
IntlTelInputModule,
...
]
<div class="container">
<form #form="ngForm">
<intl-tel-input [preferredCountries]="['nl', 'gb', 'de', 'be']" [enablePlaceholder]="true" name="phoneNumber" ngModel></intl-tel-input>
</form>
<pre>{{ form.value | json }}</pre>
</div>