Angular for table replacement

Is there a specific rule for a directive that handles <table>

?

I don't know why I can't create a directive that will replace <table>

.

I've created a jsfiddle example ;

I've searched for Angular issues but couldn't find an answer. This discussion is interesting.

Edit

Why do you want to replace the table?

The real template is more complex, for example:

<div class="grid">
  <div no-result-message="items"></div>
  <table ng-transclude></table>
  <div paging="items"></div>
</div>

      

Also, I want to move ng-repeat

inside this directive instead of tr

direct;

+3


source to share


1 answer


From looking at this SO Q&A, you might be in luck if you use restrict: 'A'

in your directive definition. Although I'm not sure if it will replace the table, but I cannot figure out why you would like to do this. Also, I'm pretty sure the ability to replace elements in directives is deprecated in angular or will be in the next version.

Updated Fiddle



angular.module('myApp',[])
.controller('MyCtrl', function($scope){
    $scope.items = [
        {first: 'Foo', last: 'Bar'},
        {first: 'Baz', last: 'Zox'},
    ];
})
.directive('grid', function() {
    return {
        restrict: 'A',
        replace: true,
        transclude: true,
        template: '<table ng-transclude></table>'
    };
});

      

+1


source







All Articles