缩小AngularJS使用的HTML代码
在我的应用程序中,我不仅要缩小javascript代码,还要缩小单个javascript文件中的html模板。但我找不到任何这样做的例子缩小AngularJS使用的HTML代码,angularjs,Angularjs,在我的应用程序中,我不仅要缩小javascript代码,还要缩小单个javascript文件中的html模板。但我找不到任何这样做的例子 templates/tmpl1.html templates/tmpl2.html controllers/ctrl1.js controllers/ctrl2.js -> minify all files to "app.js" 我认为HTML代码应该转换成字符串,因为正如我所知,将HTML写入javascript文件是不可能的。Angular有一
templates/tmpl1.html
templates/tmpl2.html
controllers/ctrl1.js
controllers/ctrl2.js
-> minify all files to "app.js"
我认为HTML代码应该转换成字符串,因为正如我所知,将HTML写入javascript文件是不可能的。Angular有一个可以直接篡改的代码。
所以你可以
var myApp = angular.module('myApp', []);
myApp.run(function($templateCache) {
$templateCache.put('templates/tmpl2.html', '<strong>This is the content of the template</strong>');
});
var myApp=angular.module('myApp',[]);
运行(函数($templateCache){
$templateCache.put('templates/tmpl2.html','这是模板的内容,);
});
您可以手动创建一个.js文件,将所有模板作为字符串添加到
$templateCache
中,然后将其与所有其他.js文件合并/缩小,或者您可以(应该)使用并自动处理所有这些文件。如果您使用grunt,则有角度模板正是这样做的。()我看不出有多少人对缩小HTML感兴趣,更不用说把它放在js文件中了,尤其是当浏览器直接使用它时,它不会像处理HTML文件那样处理js文件。。。