简体   繁体   English

通过角度javascript或其他任何方式生成html css源代码

[英]generating html css source code by angular javascript or anything else

I build a drag & drop HTML Layout generator using Angular.js. 我使用Angular.js构建了一个拖放HTML布局生成器。 Now I want to save generated HTML,CSS source code removing angular.js code from only the design. 现在我想保存生成的HTML,CSS源代码仅从设计中删除angular.js代码。 Is their any solution for generating HTML, CSS code using angular.js? 他们使用angular.js生成HTML,CSS代码的任何解决方案?

Here you can use jquery to get your html like as 在这里你可以使用jquery来获得你的html

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

Remove extra tag by this way 通过这种方式删除额外的标签

//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');

Clean your html and get all html 清理你的HTML并获得所有的HTML

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

and finally save this by using https://github.com/eligrey/FileSaver.js 最后使用https://github.com/eligrey/FileSaver.js保存

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

Extra function 额外功能

//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;
};

I think this will help you. 我想这会对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM