我正在使用 Angular 7 及其 CLI 在网站上开发一个小型页面/路由器组件
。有一次我需要检查用户是否允许 flash,我这样做是这样做的:
checkFlash() {
var hasFlash = false;
try {
hasFlash = Boolean(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"));
} catch (exception) {
hasFlash = "undefined" != typeof navigator.mimeTypes["application/x-shockwave-flash"];
}
return hasFlash;
}
我在 here 上发现了这个,它工作得很好,但是现在当我清理我的应用程序时,我注意到 Angular 似乎不喜欢这个,事实上,它说 ActiveXObject
没有定义,但它仍然有效。
Super confused...
我尝试像这样链接一个实际的 flash 对象 $('embed[type="application/x-shockwave-flash"]')
或 $('embed[type="application/x-shockwave-flash"]')[0]
但运气不好,它总是返回 true。
我尝试安装额外的 npm
(s),包括 activex-support
和 activex-data-support
以及它们的 @types
表亲。设置它们后,我发现它们对我的案子没有任何帮助。
Here are the exact errors the
CLI
&VScode
-Intellisense
gave me:
VS代码:
[ts] 'ActiveXObject' 仅指类型,但在这里用作值。 [2693]
任何
命令行界面:
src/app/games/games.component.ts(51,30) 中的错误:错误 TS2304:找不到名称“ActiveXObject”。
在纯 JS 中运行时不会抛出此错误,但我环顾四周,似乎无法弄清楚如何在 Angular 2 (7 )
。也看着 here 没有运气。
Please help, completely lost here.
EDIT: Found the fix --> The answer was here listed inside the comments (will need to make minor changes)(shown below)
- change from:
checkFlash() {
var hasFlash = false;
try {
hasFlash = Boolean(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"));
} catch (exception) {
hasFlash = "undefined" != typeof navigator.mimeTypes["application/x-
shockwave-flash"];
}
return hasFlash;
}
- to:
function checkFlash() {
var hasFlash = false;
try {
var flash =
navigator.mimeTypes &&
navigator.mimeTypes["application/x-shockwave-flash"]
? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin
: 0;
if (flash) hasFlash = true;
} catch (e) {
if (navigator.mimeTypes["application/x-shockwave-flash"] != undefined)
hasFlash = true;
}
return hasFlash;
}
最佳答案
ActiveXObject 的这个问题可以解决,如下所示: 转到您的 tsconfig.json 文件并添加“scripthost”库。 然后重新编译您的应用程序。
"lib": [
"es2017",
"dom",
"scripthost"
]
关于node.js - Angular 7 中 ActiveXObject 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54157588/