【发布时间】:2019-02-13 22:39:43
【问题描述】:
我是 Angular 5 的新手,根据我的业务需要,我需要获取用户机器的 mac 地址。为此,我尝试实现以下...
参考:https://www.npmjs.com/package/macaddress
npm install --save macaddress
我已经使用 NPM 添加了这个包,并在我的 typescript 文件中添加了以下代码。
var macaddress = require('macaddress'); //added this code below my imports
ngOnInit() {
macaddress.one(function (err, mac) {
console.log("Mac address for this host: %s", mac);
});
}
添加此代码后,我无法运行我的项目,并显示带有上述错误的黑屏。
谁能帮我解决这个问题。
编辑:./node_modules/macaddress/lib/windows.js 找不到模块:错误:无法解析“D:\Projects\Angular\eCommerceWebsite\node_modules\macaddress\lib”中的“child_process” 错误@vendor.js:158535
在控制台中得到了这个。
更新:
【问题讨论】:
-
您能检查一下浏览器控制台上显示的错误吗?
-
请查看更新后的帖子@SandeepKamath
-
您是否在类型脚本文件中导入了您正在使用的新模块。你能添加你的打字稿文件的代码sn-p吗?
-
我在我的 app.component.ts 文件中使用此代码。@SandeepKamath
-
好的。基本上你需要在 app modules 类中添加一个新模块,然后在组件 ts 文件中导入。请在下面的代码 sn-p 中找到一个示例
标签: angular typescript angular5