我正在使用 angular7。我的网站需要国际电话输入 ( https://intl-tel-input.com/ )。
所以我使用以下评论来安装 CDN。
npm uninstall ng2-tel-input --save
之后我在 angular.json 中调用了 CSS 和 JS 文件
"styles": [
"node_modules/intl-tel-input/build/css/intlTelInput.min.css",
"src/styles.css"
],
"scripts": [
"node_modules/intl-tel-input/build/js/utils.js",
"node_modules/intl-tel-input/build/js/intlTelInput.min.js"
],
在“contactform.compenent.html”中添加了电话号码的输入字段
<input type="tel" class="form-control" value="" placeholder="Mobile number"
id="telnumber-field" required>
并在“app.compenent.ts”中添加了电话区的脚本
ngOnInit(){
jQuery( document ).ready( function( $ ) {
if(jQuery('#telnumber-field').length){
var input = document.querySelector("#telnumber-field");
window.intlTelInput(input, {
preferredCountries: ['in'],
separateDialCode: true
});
}
}); }
但是有一个错误来了。
src/app/app.component.ts(65,11) 中的错误:错误 TS2339:“窗口”类型上不存在属性“intlTelInput”。