Al Ex Tsm
Al Ex Tsm

Reputation: 2102

Dynamic load of templateUrl within directive

I target the right template url value inside the directive as my directive console.log() shows but the template doesn't load.

directive:

app.directive('customtemp', function($parse) {
  var x="";
   return {
        scope: {
      tempUrl:"=" 
    },       
       link: function(scope, element, attrs) {
           console.log(scope.tempUrl);  
           x = scope.tempUrl;
       },
      templateUrl: x
   }
});

Template:

<div ng-init="template = attobj.template">
  <customtemp temp-url="template">
  </customtemp>
</div>

What am I missing here, a second return for templateUrl?

Upvotes: 0

Views: 121

Answers (1)

cagica
cagica

Reputation: 679

You can use ng-include to do this, I think you can't use it like you did.

       link: function(scope, element, attrs) {
           scope.getContentUrl = function() {
                return attrs.tempUrl;
           }
       },
       template: '<div ng-include="getContentUrl()"></div>'

Upvotes: 0

Related Questions