I have look up all related questions on stackoverflow but did not find any relevant answer. Maybe it's the elephant in the room that only I can't see but after wasting an entire day on this, I would really appreciate if someone can offer some insight. I have a controller with a scope variable $scope.fruits that is using resource to post data to /fruits (contrived example)
.controller('FruitsController', ['$scope', 'addFruitsFactory', 'sliceFruitsFactory', function($scope, addFruitsFactory, sliceFruitsFactory) {
$scope.fruits = {
seasonal: "",
imported: "",
exported: ""
}
btn_serveFruits = function() {
// user selects a list of fruits from a select control in html.
// $scope.fruits is successfully bound to this select
// $scope.fruits has a list of selected fruits
addFruitsFactory.save($scope.fruits).$promise.then(
function(response) {
console.log('fruits in scope ' + $scope.fruis);
// $scope.fruits is empty here. Is it possible to access
// $scope data here so it can be passed to the next factory?
sliceFruitsFactory.slice($scope.fruits);
},
function(response) {
$scope.message = "Error : " + response.status + " " + response.statusText;
}
);
}
}
Is it possible to access $scope.fruits in the success promise returned by the resource? Your response is greatly appreciated. Thanks!