angular.module('myApp', [])
.controller('myCtrl', ['$scope','$templateCache', function($scope,$templateCache){
var tmp = '<h4>lovestory</h4>'
+ '<p>这是直接调用$templateCache服务获取模板文件的方式</p>'
+ '<a href="http://www.baidu.com">服务启用templateCache方式</a>';
$templateCache.put('lovestory.html',tmp);
}])
<script type="text/ng-template" id="lovestory.html"> <h4>lovestory</h4> <p>这是script标签获取模板文件的方式</p> <a href="http://www.baidu.com">标签启用templateCache方式</a> </script>
<div ng-include="'lovestory.html'" class="well"></div>
<div ng-include="'lovestory.html'" class="well"></div>
angular.module('myApp', [])
.directive('templateDemo', ['$log', function($log){
return {
restrict: 'A', // E = Element, A = Attribute, C = Class, M = Comment
templateUrl: 'butterfly.html',
replace: true,
link: function($scope, iElm, iAttrs, controller) {}
}
}])
angular.module('administratorApp',[])
.config(function ($routeProvider,$locationProvider) {
$locationProvider.html5Mode(false);
$routeProvider
.when('/manage', {
templateUrl: 'views/manage.html',
controller: 'ManageCtrl'
})
.when('/diary/:key', {
templateUrl: 'views/diaryDetail.html',
controller: 'DiaryDetailCtrl',
})
.when('/diary', {
templateUrl: 'views/diaryList.html',
controller: 'DiaryListCtrl'
})
.when('/publish/:key', {
templateUrl: 'views/update.html',
controller: 'UpdateCtrl'
})
.when('/publish', {
templateUrl: 'views/publish.html',
controller: 'PublishCtrl'
})
.when('/record', {
templateUrl: 'views/record.html',
controller: 'RecordCtrl'
})
.otherwise({
redirectTo: '/diary'
});
});
$scope.$on('$locationChangeStart',function(){
$templateCache.remove('****.html');
})
\$templateCache = \$cacheFactory('template');
| 方法 | 功能 |
|---|---|
| put | 向内存写入模板内容 |
| get | 从内存获取模板内容 |
| remove | 传入key值,删除对应模板内容 |
| removeAll | 删除所有模板内容 |
| destroy | 解除key-value对应关系,但不释放内存 |
| info | 模板缓存对象的信息 |
module.exports = function(grunt){
grunt.initConfig({
html2js : {
simple : {
options : {
base : '',
module : 'templateStore'
},
files : [{
src : ['views/*.html'],
dest : 'build/scripts/templateStore.js'
}]
}
}
});
grunt.loadNpmTasks('grunt-html2js');
grunt.registerTask('default',['html2js']);
}
angular.module("views/diaryList.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("views/diaryList.html", '*******'
}]);
<script type="text/ng-template" id="views/diaryList.html"> *********** </script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有