I want to use Google libphonenumber in my angular project using Typescript. I have searched a lot on internet and found a lot of stuff but could not find anything that could serve my purpose.
Most of the content available shows the code in JavaScript. If I use the same code in typescript, it shows lot of error like 'cannot find name require' or 'module not found'. Please tell me how/where/what to write the code.
Also, plz tell me which package to install as there are many - libphonenumber, google-libphonenumber, angular-libphonenumber
相关问题
- Angular RxJS mergeMap types
- void before promise syntax
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- Ignore Typescript errors in Webpack-dev-server
- How to update placeholder text in ng2-smart-table?
相关文章
- angular脚手架在ie9+下兼容问题
- angular 前端项目 build 报错 "Cannot find module 'le
- Cannot find module 'redux' 怎么解决?
- Angular Material Stepper causes mat-formfield to v
- After upgrade to Angular 9 cannot find variable in
- is there any difference between import { Observabl
- Suppress “Circular dependency detected” suppress w
- How can you get current positional information abo
you may either go with libphonenumber or google-libphonenumber as both of this library having a good number of installs also google-libphonenumber seems to be more powerful
when dealing with CommonJS libraries, in TypeScript just like this google-libphonenumber, I'd like to suggest 2 ways about it (Tested by me and works well).
First time I'd like to suggest to install from NPM just like this:
npm install --save google-libphonenumber
.Then here we go the 2 ways of using it:
1st Method
Just import it directly
2nd Method
You still can make the power of Typescript typing or just use the existing one by:
npm install --save-dev @types/google-libphonenumber
.Since you said that you using Angular, so you can declare that typing just installed at
src/tsconfig.app.json
( I am using Angular Version 7 ). Here is an example I have made:Then you can just import it like usual, in Typescript "typings" way like follow: