Pradeep Pradeep - 16 days ago 11
AngularJS Question

Angularjs $routeProvider Config

I have a simple angularjs App called testAPP. In it I have a constant called URLS, which I may also use in other services of this app. now I need to use the URLS.DASHBOARD_URL inside templateUrl of the $routeProvider. Is it possbile? If not, then whats the easiest way to achieve this?

(function () {
angular.module('testAPP', [])

.constant("URLS", {
"DASHBOARD_URL": '/modules/dashboard/dashboardUI.html'
})

.config(['$routeProvider', function ($routeProvider) {

$routeProvider
.when('/', {
title: 'website',
templateUrl: URLS.DASHBOARD_URL, //Here i need to use
controller: '',
})

}]);

})();

Answer

You can inject constant into config and use it, as follows:

(function () {
   angular.module('testAPP', [])

   .constant("URLS", {
        "WEBSITE": '/modules/dashboard/dashboardUI.html'
    })

    .config(['$routeProvider','URLS', function ($routeProvider,URLS) {

     $routeProvider
       .when('/', {
           title: 'website',
           templateUrl: URLS.WEBSITE,
           controller: '',
        })

  }]);
 })();