Skip to content Skip to sidebar Skip to footer

How To Build A Full Dynamic Template In Angular?

I want to ask the community of angular to help me to find the best way to solve this problem : I have data like this in json : { 'id': '0001', 'type': 'donut', 'name'

Solution 1:

Yes, you should create directive with field config like this:

var config = [{
   title: 'Column name',
   renderer: function valueRenderer(item){ return item.id}
}];

and render it like

<table>
 <thead>
    <th ng-repeat="column in config" ng-bind="column.title">
 </thead>
 <tbody>
    <tr ng-repeat="item in data">
       <td ng-repeat="column in config" ng-bind="column.renderer(item)"></td>
    </tr>
 </tbody>
</table>

and wrap it inside directive

<my-dir config="ctrl.config" data="ctrl.data"></my-dir>

directive:

module.directive('myDir', function(){
   return {
      restrict: 'E',
      scope: {
         data: '=',
         config: '='
      },
      template: '<table ....'
   };
});

Post a Comment for "How To Build A Full Dynamic Template In Angular?"