角 - 自定义元素不工作的Firefox和微软边缘和Internet Explorer中

问题描述 投票:1回答:3

我想这Angular Elements Demo

我下载,安装,并建立了演示地方。

然后,用下面的代码:

<!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和!它工作正常!

也许我需要包括像polyfill一些JavaScript文件?我想互联网上其中一些建议,但没有成功。

它也没有在Microsoft EdgeInternet 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

但没有成功

关于如何解决这个任何想法?

谢谢你的帮助!

javascript angular typescript web-component custom-element
3个回答
2
投票

我得到了我的自定义元素的项目在其他浏览器的工作通过移除encapsulation: ViewEncapsulation.Native


1
投票

自定义要素是通过polyfills(见浏览器支持)是Chrome,Opera和Safari浏览器,以及其他的浏览器目前支持的网络平台功能。

所以,你应该添加polyfills与Firefox的工作, 边缘...

Browser support for custom elements

注:自定义元素默认情况下,在Chrome和Opera的支持。 Firefox是非常接近;如果设置dom.webcomponents.enabled和dom.webcomponents.customelements.enabled到真正的喜好,他们目前已经上市。 Firefox的实施计划将被默认60/61版本启用。 Safari浏览器到目前为止只支持自主定制的元素,和边缘正致力于实现为好。

Official Docs.


-1
投票

角自定义元素不支持IE浏览器。这里是一个解决方法,以自定义角4+应用引导,并将它与IE浏览器的支持。

https://hongbinhb.blogspot.com/2019/02/how-to-deploy-two-or-more-angular-6.html

© www.soinside.com 2019 - 2024. All rights reserved.