2015-04-12 3 views
6

Buduję przeciągnij & upuść generator HTML Layout za pomocą Angular.js. Teraz chcę zapisać wygenerowany kod HTML, kod źródłowy CSS usuwając kod angular.js tylko z projektu. Czy istnieje jakieś rozwiązanie do generowania kodu HTML, CSS za pomocą metody angular.js?Generowanie kodu źródłowego html css przez kątowe javascript lub cokolwiek innego

+0

Nie ma określonego sposobu na usunięcie kodu angularjs na podstawie ujęcia. Znajdź atrybut lub klasę i usuń je. – Shohel

Odpowiedz

1

Tutaj można użyć jQuery aby uzyskać html jak jak

var allContent = $('.page-content').clone(); 

Usuń dodatkowy tag w ten sposób

//remove all angular class 
allContent.find("div[class^='ng-'],div[class*='ng-']").each(function() { 
    //check and remove class 
}); 

//remove all ng-model attribute ans so no 
allContent.find('*[ng-model]').removeAttr('ng-model'); 

czyścić html i uzyskać wszystkie html

allContent.htmlClean(); 
var customPageContent = allContent.html(); 

i wreszcie zapisz to, używając https://github.com/eligrey/FileSaver.js

var blob = new Blob([customPageContent], { 
       type: "application/xhtml+xml;charset=charset=utf-8" 
      }); 
saveAs(blob, fileName + ".html"); 

Dodatkowa funkcja

//clear your html 
$.fn.htmlClean = function() { 
    this.contents().filter(function() { 
     if (this.nodeType != 3) { 
       $(this).htmlClean(); 
       return false; 
      } else { 
       this.textContent = $.trim(this.textContent); 
       return !/\S/.test(this.nodeValue); 
      } 
     }).remove(); 
     return this; 
}; 

Myślę, że to pomoże.

Powiązane problemy