微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

对于角度为2或更高的@ angular-libphonenumber,是否有任何样本?

我正在尝试创建一个格式化和验证我的angualr 4应用程序中的电话号码的指令,正在寻找一些入门指导.

解决方法

编辑(15.03.2018) – 谢谢@Joseph Webber

首先,你必须安装libphonenumber-js,它是google-libphonenumber的包装器,可以在Angular 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上添加了工作演示:

libphonenumber-demo-angular2

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐