2

I want to add dynamic directive inside another directive tempalte. As you see I want to add another directive inside a directive template How do add those dynamic directive there

Please help

return {
restrict: 'AE',
require :'^awkGrid',
templateUrl: 'views/shutter.html',
link : function(scope, element, attr, controllerInstance){

    //Set the header
    scope.items = [];
    angular.forEach(scope.rowData, function(value, key) {

        var obj = {
            key : key,
            value : value
        };


        template = <country name="'+value.country+'" id="'+key+'"></country>;
        scope.items.push(template);
    });
};
//Inside shutter.html file
 <div data-ng-repeat="item in items" class="ag-row action-row"
 ng-class-odd="'ag-row-even'"
 ng-class-even="'ag-row-odd'"
 ng-class="{'ag-row-selected':$index == selectedRow}"
 ng-click="setClickedRow($index,$event)">
<div class="ag-cell">
            {{item}} //Not working ,Prinitng the string
    <country name="india" id="-1"></country> //Working
</div>

Icet
  • 678
  • 2
  • 13
  • 31

2 Answers2

0

You must have to recompile your directive. Add folowing code at the end of link function:

$compile(element.contents())(scope);

Answer is in here.

Of course, you have to add service $compile to your directive as a dependency.

Prashant Pokhriyal
  • 3,727
  • 4
  • 28
  • 40
Niezborala
  • 1,857
  • 1
  • 18
  • 27
0

To dynamically switch out the entire template of a directive you have to set the element's html to the desired new template and then pass the element's contents into $compile to bind it with the $scope.

element.html('<h1>Dynamic Content</h1>').show();

$compile(element.contents())($scope);

This should all be defined in the link function of the directive in question.

hally9k
  • 2,423
  • 2
  • 25
  • 47