首页 > Web开发 > 详细

[AngularJS] Taking control of your templates using $templateCache

时间:2015-03-07 18:31:29      阅读:432      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!