1

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?

1 Answer 1

3

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...
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.