angularjs - How to echo JSON array as Smart Table data with Angluarjs -


i'm pretty new angular, , trying build table using smart table based on data i'm fetching rest api. can build table fine manually entered data, when try insert json array of data server resulting table empty.

currently have following set up: datafactory.js - calls api , gets json response:

app.factory('datafactory', ['$http', function($http) {    var urlbase = 'http://myurl.com/api';   var datafactory = {};    datafactory.getorders = function() {     return $http.get(urlbase + '/orders');   };    return datafactory; }]); 

my view basic , looks using smart table extension:

<div ng-controller="maincontroller">     <table st-table="orderstable" class="table table-striped">         <thead>         <tr>             <th st-sort="createdby">name</th>             <th st-sort="id">id</th>             <th st-sort="state">state</th>         </tr>         </thead>         <tbody>         <tr ng-repeat="row in orderstable">             <td>{{row.createdby}}</td>             <td>{{row.id}}</td>             <td>{{row.state}}</td>         </tr>         </tbody>     </table> </div> 

and maincontroller.js processes , stores data, , builds table:

app.controller('maincontroller', ['$scope', 'datafactory', function($scope, datafactory) {   $scope.status;   $scope.orders;   getorders();    function getorders() {     datafactory.getorders()       .success(function(ord) {         $scope.orders = ord;       })       .error(function(error) {         $scope.status = 'unable load order data: ' + error.message;       });   }    $scope.orderstable = [     // if build data manually table builds using following 3 lines     //{createdby: 'laurent', id: '56433', state: 'open')},     //{createdby: 'blandine', id: '34367', state: 'open')},     //{createdby: 'francoise', id: '34566', state: 'closed'}     //... want data come json array returned factory this:      $scope.orders   ]; }]); 

what doing wrong? how can data show in table?

in success callback updating $scope.orders , not $scope.ordertable. way use promise function instead of success , error callback (extract angularjs doc):

the $http legacy promise methods success , error have been deprecated. use standard method instead. if $httpprovider.uselegacypromiseextensions set false these methods throw $http/legacy error.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -