angularjs - data.data for reading my json -
i have factory:
'use strict'; angular.module('testcon').factory('userservice', function ($http) { return { getall: function () { return $http.get('http://localhost:1337/api/user'); } } });
and controller:
'use strict'; angular.module('testcon').controller('usercontroller', function ($scope, userservice) { $scope.users = []; userservice.getall().then( function (data) { $scope.users = data.data; }, function (err) { } ); });
can somehow avoid data.data
have data
. forces me data.data
in order see in scope?
simply can't avoid that. make 1 time change returning response.data
getall
method. consumer direct data.
code
angular.module('testcon').factory('userservice', function ($http) { return { getall: function () { return $http.get('http://localhost:1337/api/user').then(function(response){ return response.data }); } } });
Comments
Post a Comment