Guess the best way is to just cross the DOM
Here is the code that I use if someone wants to use it, improve it or completely change it ...
The attr and class lists are obviously not complete.
function cleanAngularStuff(el) { //recursive function var remClassList = ['ng-scope', 'ng-model', 'ng-binding', 'ng-isolate-scope'] var remAttrList = ['ng-repeat'] // If node is a comment just remove it if (el.nodeType == 8) { el.parentNode.removeChild(el); } // If its an element remove extra attributes and classes and recurse children else if (el.nodeType == 1) { // Remove extra classes. If none is left remove class attribute for (var i = 0; i < remClassList.length; i++) { el.classList.remove(remClassList[i]); if (el.classList.length == 0) { el.removeAttribute('class') } } // Remove attributes for (var h = 0; h < remAttrList.length; h++) { el.removeAttribute(remAttrList[h]) } // Recurse children for (var i = 0, len = el.childNodes.length; i < len; i++) { cleanAngularStuff(el.childNodes[i]) // If child comment is removed decrease cursor if (len > el.childNodes.length) { len = el.childNodes.length i-- } } } }
source share