如何将$ templateCache用于ui-router中使用的部分?

时间:2017-12-06 04:46:14

标签: angularjs angular-ui-router angular-templatecache

.state(' pages',{       网址:' / pages',       templateUrl:' views / common.html'     })

<script type="text/ng-template" id="common.html">

如何使用Ui-router来使用它?

1 个答案:

答案 0 :(得分:0)

对你有帮助

var myApp = angular.module('testApp', []);

myApp.run(['$templateCache',function($templateCache) {
  $templateCache.put('common.html', ' <p>how to use this using Ui-router?</p>');
   $templateCache.put('views/common.html', ' <p>how to use this using Ui-router?</p>');
}]);

myApp.config(['$stateProvide','$templateCache',function($stateProvider,$templateCache){
$stateProvider.state ('pages',
     { url: '/pages',
       template: $templateCache.get('common.html')   
     })
.state ('pages', 
     { url: '/pages', 
       templateUrl: 'views/common.html'
     })
}]);

myApp.controller('testCtrl',function($scope){
})

    <body ng-app="testApp" ng-controller="testCtrl">

    </body>