我试过这个角度元素演示
我在本地下载、安装并构建了该演示。
然后,使用以下代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Angular Elements Demo</title>
</head>
<body>
<hello-world name="Anna"></hello-world>
<script src="dist/main.js"></script>
<script>
const helloCp = document.querySelector('hello-world');
helloCp.addEventListener('hi', (data) => {
console.log(data.detail);
});
setTimeout(() => {
helloCp.setAttribute('name', 'Marc');
}, 1000);
</script>
</body>
</html>
然后我试穿了Mozilla Firefox
但出现以下错误:
"ReferenceError: customElements is not defined"
另一方面,我尝试过Google Chrome
和 !!!它工作正常!
也许我需要包含一些 Javascript 文件,例如polyfill
?
我尝试了互联网上推荐的一些方法,但没有成功。
它也不起作用Microsoft Edge
and Internet Explorer
.
有没有办法让代码在 Firefox 上运行而不调整其默认配置?
我的意思是,在 Firefox 上:about:config
dom.webcomponents.customelements.enabled: true
dom.webcomponents.shadowdom.enabled: true
我尝试添加以下 Javascript 文件:
https://github.com/webcomponents/webcomponentsjs/blob/v1/webcomponents-lite.js
正如这里推荐的:
https://www.webcomponents.org/polyfills
但没有成功
关于如何解决这个问题有什么想法吗?
感谢您的帮助!