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

How to use $templateCache for partials that are used in ui-router?

.state ('pages', { url: '/页面', 模板网址:'views/common.html' })

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

如何使用 Ui-router?

对你有帮助

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>