Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有angular.js的Web组件&;IE11兼容性_Javascript_Angularjs_Internet Explorer_Clone_Web Component - Fatal编程技术网

Javascript 带有angular.js的Web组件&;IE11兼容性

Javascript 带有angular.js的Web组件&;IE11兼容性,javascript,angularjs,internet-explorer,clone,web-component,Javascript,Angularjs,Internet Explorer,Clone,Web Component,我有一个angular.js应用程序,我想在其中初始化一个web组件 它在其他浏览器上运行得非常好,但IE11似乎在这方面存在问题 document.importNode angular.js onInit函数: vm.$onInit = function() { vm.params = $location.search(); if(vm.params.merchantId && vm.pa

我有一个angular.js应用程序,我想在其中初始化一个web组件

它在其他浏览器上运行得非常好,但IE11似乎在这方面存在问题

document.importNode

angular.js onInit函数:

           vm.$onInit = function() {
                vm.params = $location.search();

                if(vm.params.merchantId  && vm.params.apiToken && vm.params.amount && vm.params.orderId) {
                    vm.mid = vm.params.merchantId;
                    vm.apiToken = vm.params.apiToken;
                    vm.amount = vm.params.amount;
                    vm.orderId = vm.params.orderId;

                    let template = document.querySelector('#template');
                    let clone = document.importNode(template.content, true);
                    let cmp = clone.querySelector('cmp-request');
                    
                    cmp.setAttribute('mid', vm.mid);

                    template.replaceWith(clone);
                    
                }
            }
HTML:



有没有其他方法可以在不使用importNode的情况下克隆web组件并在内部传递参数,这样它就可以在IE11上工作?

IE11不支持
importNode
replaceWith
。对于
importNode
,我使用
children
获取
的子元素,以获取IE 11中的web组件。对于
replaceWith
,我在IE 11中支持它

您可以使用伪值参考我的代码示例:

函数ReplaceWithPolyfill(){
“使用strict”;//用于safari,IE>10
var parent=this.parentNode,
i=arguments.length,
当前节点;
如果(!父项)返回;
if(!i)//如果没有参数
parent.removeChild(本);
而(i-){//i-递减i并返回递减之前i的值
currentNode=参数[i];
if(当前节点的类型!=='object'){
currentNode=this.ownerDocument.createTextNode(currentNode);
}else if(currentNode.parentNode){
currentNode.parentNode.removeChild(currentNode);
}
//下面的“i”值在减量之后
if(!i)//如果currentNode是第一个参数(currentNode==参数[0])
replaceChild(currentNode,this);
else//如果currentNode不是第一个
parent.insertBefore(currentNode,this.nextSibling);
}
}
如果(!Element.prototype.replaceWith)
Element.prototype.replaceWith=ReplaceWithPolyfill;
if(!CharacterData.prototype.replaceWith)
CharacterData.prototype.replaceWith=ReplaceWithPolyfill;
如果(!DocumentType.prototype.replaceWith)
DocumentType.prototype.replaceWith=ReplaceWithPolyfill;
var template=document.querySelector(“#template”);
如果(navigator.userAgent.indexOf('MSIE')!=-1 | | navigator.appVersion.indexOf('Trident/'))>-1{//IE11
var clone=template.children[0];
clone.setAttribute('mid','test');
}否则{
var clone=document.importNode(template.content,true);
var cmp=clone.querySelector('cmp-request');
cmp.setAttribute('mid','test');
}
模板。替换为(克隆)


IE 11不支持
importNode
replaceWith
。对于
importNode
,我使用
children
获取
的子元素,以获取IE 11中的web组件。对于
replaceWith
,我在IE 11中支持它

您可以使用伪值参考我的代码示例:

函数ReplaceWithPolyfill(){
“使用strict”;//用于safari,IE>10
var parent=this.parentNode,
i=arguments.length,
当前节点;
如果(!父项)返回;
if(!i)//如果没有参数
parent.removeChild(本);
而(i-){//i-递减i并返回递减之前i的值
currentNode=参数[i];
if(当前节点的类型!=='object'){
currentNode=this.ownerDocument.createTextNode(currentNode);
}else if(currentNode.parentNode){
currentNode.parentNode.removeChild(currentNode);
}
//下面的“i”值在减量之后
if(!i)//如果currentNode是第一个参数(currentNode==参数[0])
replaceChild(currentNode,this);
else//如果currentNode不是第一个
parent.insertBefore(currentNode,this.nextSibling);
}
}
如果(!Element.prototype.replaceWith)
Element.prototype.replaceWith=ReplaceWithPolyfill;
if(!CharacterData.prototype.replaceWith)
CharacterData.prototype.replaceWith=ReplaceWithPolyfill;
如果(!DocumentType.prototype.replaceWith)
DocumentType.prototype.replaceWith=ReplaceWithPolyfill;
var template=document.querySelector(“#template”);
如果(navigator.userAgent.indexOf('MSIE')!=-1 | | navigator.appVersion.indexOf('Trident/'))>-1{//IE11
var clone=template.children[0];
clone.setAttribute('mid','test');
}否则{
var clone=document.importNode(template.content,true);
var cmp=clone.querySelector('cmp-request');
cmp.setAttribute('mid','test');
}
模板。替换为(克隆)


IE11需要一个polyfill IE11需要一个polyfill谢谢,这真的很有帮助!谢谢,这真的很有帮助!
<template id="template"> 
    <cmp-request></cmp-request>
</template>