angular2如何使用shadow dom,而某些流行的浏览器不支持它?

Ali*_*ian 4 web-component shadow-dom angular

来自文件:

实例化组件时,Angular

creates a shadow DOM for the component.
loads the selected template into the shadow DOM.
creates a child Injector which is configured with the appInjector for the Component.
Run Code Online (Sandbox Code Playgroud)

但是,据我所知,IE,Safari甚至Firefox的默认配置都不支持shadow DOM !
考虑到shadow DOM不是可以通过js库或其他东西轻松添加到浏览器的功能,如何对angular2进行浏览器支持?

PS:原谅我打电话给IE和Safari(特别是IE)流行的浏览器!

shm*_*mck 7

Angular 2有两种Shadow DOM模式:模拟和本机模式.换句话说,没有Shadow DOM支持的浏览器将获得有效但较慢的polyfill.

讨论源代码

  • [Polymer](https://github.com/webcomponents/webcomponentsjs)将是在所有现代浏览器中填充Shadow DOM的库的一个很好的例子.基本上,polyfill看起来像这样:`(function(){if('HTMLElement.prototype中的'createShadowRoot'){return;} HTMLElement.prototype.createShadowRoot = function(){return this.shadowRoot = this;};}}() );` (2认同)