javascript - Displaying a table's row in a div element using AngularJS -
i have database table many rows, each 5 fields each. have <div>
element i'd display 1 row's fields in. best way retrieve row table , have div display row's fields?
currently have service retrieves rows table, controller calls aforementioned service, , within controller have each of row's fields. here's mean:
// service ... gettablerows: function(callback) { $http.post('../php/gettablerows.php') .success(function(data, status, headers, config) { callback(data); }) .error(function(errordata) { console.log("error: " + errordata); }); } // controller ... myservice.php.gettablerows(function(gettablerowsresponse){ // gettablerowsresponse contains of rows in table in array //gettablerowsresponse[0].name; //gettablerowsresponse[0].id; //gettablerowsresponse[0].age; //gettablerowsresponse[0].department; //gettablerwosresponse[0].imageurl; }); // view ... <div class="widget"> //how access fields here? </div>
you can set row response controller scope , access in view. in view can use angularjs ng-repeat directive loop through records table response , render required data.
js
myservice.php.gettablerows(function(gettablerowsresponse){ // gettablerowsresponse contains of rows in table in array $scope.tableresponse = gettablerowsresponse; });
view
<div class="widget" ng-repeat="row in tableresponse"> <!-- render ui want --> name: {{row.name}} age: {{row.age}} ... ... </div>
Comments
Post a Comment