I'm learning AngularJS. My services:
services.factory('Model', ['$resource',
function ($resource) {
return $resource('model/:id', {}, {});
}
]);
services.factory('Department', ['$resource',
function ($resource) {
return $resource('department/:id', {}, {});
}
]);
services.factory('Price', ['$resource',
function ($resource) {
return $resource('price/:id', {}, {});
}
]);
My controller:
controllers.controller('SafeNewCtrl', ['$scope', '$location', 'Safe', 'Model', 'Department', 'Price',
function ($scope, $location, Safe, Model, Department, Price) {
$scope.models = Model.query();
$scope.departments =Department.query();
$scope.prices = Price.query();
// It doesn't work. console.log($scope.models[0] 'and other') = undefined.
$scope.safe = {model: $scope.models[0], department: $scope.departments[0], price: $scope.prices[0]};
$scope.save = function () {
var safe = new Safe($scope.safe);
safe.$save(function () {
$location.path('list/f');
})
}
}
]);
I got array of Resources after each query(). How can I get normal JSON as array and first objects of arrays to set to the $scope.safe?