Pradeep
Pradeep

Reputation: 641

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: '',
                    })

}]);

})();

Upvotes: 0

Views: 58

Answers (1)

Kalpesh Patel
Kalpesh Patel

Reputation: 2822

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: '',
        })

  }]);
 })();

Upvotes: 2

Related Questions