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

134 Views Asked by At

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

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

how to use this using Ui-router?

1

There are 1 best solutions below

7
On BEST ANSWER

It will be helpful to you

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>