0

I create a directive to dynamically generate tables... the directive should contact the data service an then show some rows, the rows head is id, name, regions.

<planets data="{ view: 'planets', params: ['id','name','regions'] }"></planets>


test.directive('planets', function () {
    return {
        restrict: 'E',
        scope: {
            'data' : '='
        },
        template: '<div>{{data.params}}!</div>'
    }

});

i need a advice how to generate the

   <table>
      <tr>
         <th>id</th>
         <th>name</th>
         <th>regions</th>
      </tr>
   </table>

dynamic? and how to pass the data out of the service to the

iam not shur to use template or link?

thanks!

EDIT:

test.controller('projects', function ($scope, DataService, $resource) {

    DataService.query(function(response) {
        $scope.projects = response;
    });

});

test.directive('planets', function () {
    return {
        restrict: 'E',
        scope: {
            'data' : '='
        },
        templateUrl: 'templates/table.html'
    };

});
3
  • Is 'data' : '=' working for you? Commented Jan 25, 2014 at 13:01
  • yes it is...my template show the params array! Commented Jan 25, 2014 at 13:23
  • People also had problem that you have, stackoverflow.com/questions/18357370/… Commented Jan 25, 2014 at 19:30

1 Answer 1

1

It depends how dynamic you need to be. However, to generate your sample, you only need an ng-repeat inside the template:

template: '<table><tr><th ng-repeat="param in data.params">{{param}}</th></tr></table>'
Sign up to request clarification or add additional context in comments.

2 Comments

How i get the scope.projects in my directive? Only with ng-controller? or is there another way? i updated first post!
just add another directive scope variable: projects: "=" and set a projects attribute. same way as you are doing for data.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.