Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I have an angular component I am building in angular 1.5. It looks like this:

var module = angular.module("ncRelationshipSearch");

module.component("relationshipSearch", {
    templateUrl: <need to dynamically assign>,
    controllerAs: "vm",
    controller: ['config', function(config){
         ... config provider here knows about templateURL...
    }
}

I need the templateUrl to be assignable somehow. I have a config provider that could supply the URL but I can't inject it at the point of component definition. Is there a way to get the URL in through the bindings or set it later in the controller?

share|improve this question
up vote 2 down vote accepted

You can have function for templateUrl where you can inject service/factory. You can actually inject config provider over the templateUrl function.

module.component("relationshipSearch", {
    templateUrl: function(config){
       //play here with service variables generate templateUrl
       //other code can also lie here. :)
       return config.myTemplatUrl;
    },
    controllerAs: "vm",
    controller: ['config', function(config){
         ... config provider here knows about templateURL...
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.