0

I am trying to load directive inside another directive dynamically, so I am trying to use ng-repeat for the below, where {{item.directiveName}} is the inner directive name.

<card ng-repeat="item in items" {{item.directiveName}} title="{{item.title}}">

The problem is that the {{item.directiveName}} is not evaluated, it stays as it is. I think because it is not a value of an attribute, it is an attribute.

Is there any way for this expression to be evaluated or this is not supported by angularjs?

Ghyath Serhal
  • 7,466
  • 6
  • 44
  • 60

2 Answers2

1

This should do it, depending on the card directive.

<div ng-repeat="item in items">
<card  {{item.directiveName}} title="{{item.title}}"> </card>
</div>
Mike Feltman
  • 5,160
  • 1
  • 17
  • 38
  • Where's the card directive coming from? – Mike Feltman Oct 06 '15 at 14:47
  • it is a custom directive that I developed. Forget about the card directive, you can put a div instead the card directive, and you will face the same problem. – Ghyath Serhal Oct 06 '15 at 14:48
  • Is card your directive as well? Anyways, I think this approach would not work because you assign value after the compile stage. For starters, if card is your directive, try adding a breakpoint in its link function and check the attributes and change your html to: – Meir Oct 06 '15 at 14:52
  • 1
    So you're trying to dynamically load a directive in a directive basically? I don't think Angular will do that out of the box. This codepen: http://jsfiddle.net/ftfish/KyEr3/ should get you pretty close. – Mike Feltman Oct 06 '15 at 14:52
  • yeah, that is right. I am trying to load a directive inside another directive dynamically. – Ghyath Serhal Oct 06 '15 at 15:01
0

try to assign it to an attribute

<card ng-repeat="item in items" data="{{item.directiveName}}" title="{{item.title}}">

    <card ng-repeat="item in items" myAttr="{{item.directiveName}}" title="{{item.title}}">
Isaac
  • 218
  • 1
  • 15
  • If I assign it to to an attribute, it will work, but I do not want to do it, because this is the name of another directive that should be executed. – Ghyath Serhal Oct 06 '15 at 14:50