Compadre Compadre - 1 year ago 104
AngularJS Question

Angularjs add constant value to directive's templateUrl

I got constant in module :

angular.module('identicaApp.common', ['ngResource', 'ngCookies'])
.constant('ROOT_PATH', '/static/angular/identica/')

so I want to use it in another directive, in templateUrl attribute, something like this:

angular.module('identicaApp.registration.player', ['identicaApp.common'])
.component('registerPlayer', {
templateUrl: ROOT_PATH + 'registration/register_player/register_player.html',

so how can i do this?

Answer Source

In component templateUrl function you can have dependencies injected and use it to form templateUrl.


angular.module('identicaApp.registration.player', ['identicaApp.common'])
  .component('registerPlayer', { 'registration/register_player/register_player.html',
    templateUrl: function(ROOT_PATH){ //<-- add dependency in function
       return ROOT_PATH + 'registration/register_player/register_player.html',

Check here in doc where clearly mentioned that templateUrl is injectable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download