angularjs - How to make a template repeat -
i have directive, want template show rows data set
app.directive('exampledirective', [ 'testprovider', 'testfactory', function (testprovider, testfactory) { return { restrict: 'e', template: '<tr><td>{{name}} </td><td>{{surname}}</td></tr>', replace: true, link: function(scope, elm, attrs) { var dat= testfactory.datareturn(); (var = 0; < dat.length; i++) { scope.name = dat[i].name; scope.surname = dat[i].surname; console.log(dat[i]); } // alert("hah"); } }; }]);
how can make repeat ng-repeat ?
assuming service returning promise. here simple code repeat data in table.
app.directive('exampledirective', [ 'testprovider', 'testfactory', function (testprovider, testfactory) { return { restrict: 'e', template: '<table ng-repeat="person in persons"><tr><td>{{person.name }} </td><td>{{person.surname}}</td></tr></table>', replace: true, link: function(scope, elm, attrs) { testfactory.datareturn().then(function(resp){ scope.persons = resp.data; }); } }; }]);
Comments
Post a Comment