javascript - $resource responses an empty array in AngularJS -


i want display table items json data. i've created service return json data. in ctrl i'm doing query service receive array data. bit confused. because put response in new js-variable js variable in scope variable. i'm using scope variable in ngrepeat directive in html file , have displays data in table don't that.

service:

myapp.factory('myservice', function ($resource) {     return $resource('data/mydata.json'); }); 

ctrl:

var mydata = myservice.query(function () {         $log.info('[result:]', mydata); //console shows expected data     });  $scope.datas = mydata; $log.info('result2:', $scope.datas); //console shows empty array 

view:

<tr ng-repeat="item in filtereddata = (datas | filter:search)>     <td>{{ item.id }}</td>     <td>{{ item.name }}</td> </tr> 

usually data have contained in variable mydata, aren't they?

edit: new problem is, list won't sorted. i'm using orderby filter angularjs doc website.

your

myservice.query.... 

is async call. js not wait response , executes next line

$scope.datas = mydata; 

hence empty array.

change code to:

var mydata = myservice.query(function () {     $log.info('[result:]', mydata); //console shows expected data     $scope.datas = mydata;     $log.info('result2:', $scope.datas); }); 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -