angularjsangular-ui-routerangular-templatecache

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


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

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

how to use this using Ui-router?


Solution

  • 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>