javascript - AngularJS - Using .Then Instead of .Success is not working with HTTP function -
i've been searching lot topic couldn't find solution still. believe not handling promise properly. have angularjs mvc model working fine when handle api call .success when changed .then ( because other depreciated ) doesn't work. can see in http-server log code below still json file , using simple json file testing believe did not forgot define view (like angularjs - can't access retrieved json data in view )
i tested complete http.get syntax in controller not working.
services.js
angular.module('myapp.services', []) .factory('apiservice', function($http, $q) { var myapis = {}; myapis.getfulllist = function() { return $http.get("myfile.json", {timeout: 30000, cache:false}); }; //(...) more apis here return myapis; });
controllers.js
angular.module('myapp.controllers', []) .controller("tablectrl", function($scope, $http, $q, apiservice) { var promise = apiservice.getfulllist(); promise.then( function(response) { $scope.mytable = response.records; }, function(reason) { console.log('error: ' + reason); } );
view
<div ng-controller="tablectrl"> <table border="0" style="width:100%" class="table table-striped table-condensed table-hover"> <tr> <th>id  </th> </tr> <tr ng-repeat="mytable in mytable> <td>{{mytable.id}}</td> </tr> </table> </div>
my json
{ "records" : [ { "id" : "500006", (...) }, (...) ] }
thanks time!
Comments
Post a Comment