angular-resource

AngularJS: Creating multiple factories for every endpoint?

扶醉桌前 提交于 2019-11-26 23:54:35
问题 following some examples, it appears that we can inject a factory which would contain an endpoint for a rest service like so services.factory('Recipe', ['$resource', function($resource) { return $resource('/recipes/:id', {id: '@id'}); }]); This looks great, but imagine I have other endpoints i.e. /users/:id, and /groups/:id, as you can imagine the number of different endpoints are going to increase. So it is good practice to have a different factory for each endpoint so having .. services

AngularJS resource promise

天涯浪子 提交于 2019-11-26 17:18:19
I've got a simple controller that use $resource : var Regions = $resource('mocks/regions.json'); $scope.regions = Regions.query(); I'm using this controller in a directive (in the link function) var regions = scope.regions; But regions is undefined. It's pretty logic the call is asynchronous. My question is how can i do to wait the result and regions be an array with all data ? UPDATE : Here the definition of the directive app.directive('ngMap', function() { return { restrict: 'EA', replace: 'true', scope: { }, template: '<div id="map"></div>', controller: 'AccordMapCtrl', link: function(scope

How to handle $resource service errors in AngularJS

♀尐吖头ヾ 提交于 2019-11-26 11:56:29
问题 I am making requests to my API and I am using AngularJS $resource module. It\'s different from $http so I don\'t know how to handle my errors. My service: var appServices = angular.module(\'app.services\', [\'ngResource\']); appServices.factory(\'Category\', [\'$resource\', function($resource){ return $resource(\'/apicategoryerr/?format=:format\', {}, { query: { method: \'GET\', params: { format: \'json\'}, isArray: true, } }); }]); My Controller: ... Category.query(function(data) { console

AngularJS resource promise

我们两清 提交于 2019-11-26 05:22:02
问题 I\'ve got a simple controller that use $resource : var Regions = $resource(\'mocks/regions.json\'); $scope.regions = Regions.query(); I\'m using this controller in a directive (in the link function) var regions = scope.regions; But regions is undefined. It\'s pretty logic the call is asynchronous. My question is how can i do to wait the result and regions be an array with all data ? UPDATE : Here the definition of the directive app.directive(\'ngMap\', function() { return { restrict: \'EA\',