2
我想創建用於格式化和我angualr 4應用驗證電話號碼指令,一直在尋找一些指導入門。是否有@角libphonenumber具有角爲2或更高的任何樣品?
我想創建用於格式化和我angualr 4應用驗證電話號碼指令,一直在尋找一些指導入門。是否有@角libphonenumber具有角爲2或更高的任何樣品?
首先,你必須安裝libphonenumber-js,這是谷歌,libphonenumber的準備對角2+進口的包裝。 您可以在您的應用程序安裝:根據你所使用的包管理器
npm install libphonenumber-js --save
或
yarn add libphonenumber-js
。
安裝後,您可以使用它您的組件像:
import { Component, OnInit } from '@angular/core';
import { parse, format, asYouType } from 'libphonenumber-js';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
asYouType: any;
format: any;
parse: any;
ngOnInit() {
this.asYouType = new asYouType('US').input('2133734');
this.format = format('2133734253', 'US', 'International');
this.parse = parse('(0777) 844 822', 'RO');
}
}
我加在Github上的工作演示:
我安裝使用NPM,你上面提到的,當我進口在「libphonenumber-JS」我得到的錯誤是不能優良的模塊「libphonenumber-JS」。 –
得到它謝謝! –