Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs component with dynamic templateUrl

is it possible to create a AngularJS Component with a dynamic templateUrl? Means I want to inject a service into the Component that gives me a base path to the template:

i.e.: templateUrl: configuration.baseScriptPath + '...html'

It is possible with a Directive, but how to do this with a Component?

angular.module('runtime')
    .component('textInput', {

        templateUrl: /*configuration.baseScriptPath + */'fd/components/text_input_instance.html',
        controller: [
            '$scope', '$element', 'focusInputGroup', 'configuration',
            function ($scope, $element, focusInputGroup, configuration) {
like image 405
dec Avatar asked Dec 05 '22 17:12

dec


1 Answers

Instead of templateUrl you can use template and ng-include, like this:

angular.module('runtime')
    .component('textInput', {

        template: '<div ng-include="getTemplate()">',
        controller: [
            '$scope', '$element', 'focusInputGroup', 'configuration',
            function ($scope, $element, focusInputGroup, configuration) {

           $scope.getTemplate = function () {
               return configuration.baseScriptPath + 'fd/components/text_input_instance.html';
          };
like image 78
Tomer Avatar answered Dec 21 '22 21:12

Tomer