javascript - 从 npm 包中导入 Angular 模块
问题描述
我想在应用程序中使用detect-mobile
包(https://github.com/hgoebl/mobile-detect.js/tree/v1.4.4)Angular
。
但它不能以通常的方式导入。我已经尝试了以下各项:
import { MobileDetect } from 'mobile-detect';
import MobileDetect from 'mobile-detect';
import {} from 'mobile-detect';
移动检测d.ts
文件具有以下结构:
我做错了什么,应该如何导入?另外,我将非常感谢您解释此类软件包与其他软件包的不同之处。
Stackblitz:https ://stackblitz.com/edit/angular-3qptjt
解决方案
用于导出的语法 - export = MobileDetect
- 表示该包是使用 CommonJS 样式导出编写的。请参阅此票以获取更多说明。
因此,导入它的方法是:
import * as MobileDetect from 'mobile-detect'
另外,我相信如果你使用esModuleInterop
TypeScript 编译器标志,你可以写:
import MobileDetect from 'mobile-detect'
推荐阅读
- docker - 在远程 Windows 服务器 VM 上设置 docker 容器
- jekyll - 如何在 Jekyll 中将对象添加到站点变量中?
- javascript - NodeJs 如何解决持续操作?
- python-3.x - 递归回文检查 - 调用函数时出现问题
- git - 尝试对 Azure Devops 执行 git push 时登录失败
- python - 获取特定列中具有空值的数据并删除其他空列
- firebase - 是否可以接受电子邮件作为 Firebase 中的密钥?
- types - 为什么 Rust 期望双借(`&&'a mut T`)
- ios - 应用程序上的后退按钮未出现
- php - Laravel登录 - 失败条件不起作用