I have the list of document elements. I want to change elements’ outerHtml with html. HTML is loaded from files in cycle, so I use promises. The problem is with passing the element to promise function in the cycle, because only the last element from array is passed.
...
/**
* Set outer html of element.
* @param element
* @param newHtml
*/
setOuterHtml = function(element, newHtml){
console.log("ELEMENT ", element); // always <ge-test-2></ge-test-2>
element.outerHTML = newHtml;
}
this.loadElementsToHtml = function(){
console.log(this.elements);
//[ge-survey, ge-test-1, ge-test-2]
var promises = [];
for(var i=0; i<this.elements.length; i++){
var el = this.elements[i];
// laod html from file
var elPromise = this.loadHtml(el);
// set outer html when HTML is loaded
//// problem here with el !!! always ge-test-2 element
elPromise.then(res => setOuterHtml(el,res));
promises.push(elPromise);
}
return Promise.all(promises);
}