加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 07:01:50 所属栏目:安全 来源:网络整理
导读:我正在尝试创建一个格式化和验证我的angualr 4应用程序中的电话号码的指令,正在寻找一些入门指导. 解决方法 编辑(15.03.2018) – 谢谢@Joseph Webber 首先,你必须安装libphonenumber-js,它是google-libphonenumber的包装器,可以在Angular 2上导入. 您可以将
我正在尝试创建一个格式化和验证我的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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读