retrieve json data using GET in angularjs -
i've got data stored in nosql database i'm able see in when accessing localhost:3000/countries.
i'm trying use factory in order data in json.
.factory('countries', ['$http', '$q', function($http, $q) { var countries = { get: function() { return $q(function(resolve, reject) { $http({ method: 'get', url: '/countries' }).then(function(response) { resolve(response.data); }, function(error) { reject(error); }); }); }; return countries; } ]);
and i'm attempting use controller send data appropriate url displayed isn't working expected to.
.controller('countriesctrl', function($scope, countries) { console.log(countries); countries.get(function(countries) { $scope.countries = countries; }); })
any thoughts or suggestions? thanks!
this use in project uses mongodb
cmsapp.factory("tasks", ["$resource", function($resource) { return $resource("/tasks/", {}, { save: { method: 'post', isarray: true }, 'delete': { method: 'delete', isarray: true } }); }]);
then in controller(make sure inject controller!):
$scope.tasks = tasks.query();
.query() selects of data while .get() gets on id
Comments
Post a Comment