码迷,mamicode.com
首页 > Web开发 > 详细

[AngularJS] Taking control of your templates using $templateCache

时间:2015-03-07 18:34:32      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

Using $templateCache for quickly retrieval from the cache after first time used.

 

$templateCache mainly can use two methods:

  • get(id)
  • put(id, "your html code here")

 

angular.module(‘app‘, [])
    .directive(‘myButton‘, function () {
        return {
            templateUrl: ‘timestamp‘
        }
    })
    .run(function ($templateCache) {
        $templateCache.put(‘timestamp‘, ‘<button>‘ + Date.now() + ‘</button>‘);
    });

 

or you can but your template in the <script> tag, then use templateCache.get() method:

<script type="text/ng-template" id="templateId.html">
  <button>Date.now()</button>
</script>
angular.module(‘app‘, [])
    .directive(‘myButton‘, function ($templateCache) {
        return {
            templateUrl: $templateCache.get(‘templateId.html‘)
        }
    })

 

[AngularJS] Taking control of your templates using $templateCache

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/4320658.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!