• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mpalourdio / intl-tel-input-ng / 3871837867

pending completion
3871837867

push

github

GitHub
build(deps): bump json5 from 2.2.1 to 2.2.3

3 of 3 branches covered (100.0%)

Branch coverage included in aggregate %.

22 of 22 relevant lines covered (100.0%)

19.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/lib/components/intl-tel-input.component.ts
1
/*
2
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
4
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
5
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
6
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
7
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
 */
9

10
import { AfterViewInit, Component, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core';
11
import { ControlContainer, NgForm } from '@angular/forms';
12
import intlTelInput from 'intl-tel-input';
13
import { CountryData, IntlTelInputOptions } from '../model/intl-tel-input-options';
14

15
@Component({
16
    selector: 'intl-tel-input',
17
    templateUrl: './intl-tel-input.component.html',
18
    styleUrls: ['./intl-tel-input.component.scss'],
19
    viewProviders: [{ provide: ControlContainer, useExisting: NgForm }]
20
})
21
export class IntlTelInputComponent implements AfterViewInit {
1✔
22

23
    @Input() cssClass!: string;
24
    @Input() E164PhoneNumber!: string | null;
25
    @Input() label!: string;
26
    @Input() labelCssClass!: string;
27
    @Input() name = 'intl-tel-input-name';
14✔
28
    @Input() onlyLocalized!: boolean;
29
    @Input() options: IntlTelInputOptions = {};
14✔
30
    @Input() required!: boolean;
31
    @Output() private E164PhoneNumberChange = new EventEmitter<string | null>();
14✔
32
    @ViewChild('intlTelInput') private _inputElement!: ElementRef;
33
    private _phoneNumber!: string;
34
    private _intlTelInput: any;
35

36
    private static modifyCountryData(): void {
37
        (window as any).intlTelInputGlobals.getCountryData().forEach((country: CountryData) =>
1✔
38
            country.name = country.name.replace(/.+\((.+)\)/, '$1'));
244✔
39
    }
40

41
    ngAfterViewInit(): void {
42
        if (this.onlyLocalized) {
19✔
43
            IntlTelInputComponent.modifyCountryData();
1✔
44
        }
45

46
        const intlTelInputInstance = intlTelInput;
19✔
47
        this._intlTelInput = intlTelInputInstance(this._inputElement.nativeElement, this.options);
19✔
48
    }
49

50
    get intlTelInput(): any {
51
        return this._intlTelInput;
1✔
52
    }
53

54
    get phoneNumber(): string {
55
        return this._phoneNumber;
46✔
56
    }
57

58
    set phoneNumber(value: string) {
59
        if (!!value) {
3✔
60
            this._intlTelInput.setNumber(value);
3✔
61
        }
62
        this._phoneNumber = value;
3✔
63
        this.i18nizePhoneNumber();
3✔
64
    }
65

66
    i18nizePhoneNumber(): void {
67
        this.E164PhoneNumber = null;
4✔
68
        if (this._intlTelInput.isValidNumber()) {
4✔
69
            this.E164PhoneNumber = this._intlTelInput.getNumber();
3✔
70
        }
71
        this.E164PhoneNumberChange.emit(this.E164PhoneNumber);
4✔
72
    }
73
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc