1

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

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

how to use this using Ui-router?

1 Answers1

0

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>
Kalaiselvan
  • 2,095
  • 1
  • 18
  • 31
  • Thanks for the update but here if i follow the way you have implemented, i need to write inline html like $templateCache.put('common.html', '

    how to use this using Ui-router?

    '); is there any way if we an use external html.
    – user7446266 Dec 06 '17 at 09:39
  • you can use the script template and for further reference https://docs.angularjs.org/api/ng/service/$templateCache – Kalaiselvan Dec 06 '17 at 09:42
  • ya i followed the same way but – user7446266 Dec 06 '17 at 09:47
  • yes i am unable to use templateCahe inside app.config as i am using ui-router i am importing the partials in templateurl in formszWebApp.config(function ($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise("/login"); $stateProvider .state ('common', { url: '/common', templateUrl: 'views/common.html' })}); – user7446266 Dec 06 '17 at 10:11
  • did you added `ng-route` or `ui.router` – Kalaiselvan Dec 06 '17 at 10:16
  • i am using ui-router,and have child states so i want to templatecache all the html files as i can get rid of those html files when i check them in dev tools. a 200 service requeest will be saved – user7446266 Dec 06 '17 at 10:21
  • `.config(["$stateProvider", "$urlRouterProvider","$templateCatch",function ($stateProvider, $urlRouterProvider,$templateCatch) { }])` – Kalaiselvan Dec 06 '17 at 10:23