Answer the question
In order to leave comments, you need to log in
How to save json CRUD with $resource (angularjs)?
The file reads and does not want to save changes, writes - "404 Not Found"! Why is that?! Who in the subject tell me :)
Service:
function CRUDservice($log, $resource, $http) {
this.getData = function(callback) {
var User = $resource('data/main/users.json');
var dataUsers = User.get(callback);
}
this.saveData = function(newUser) {
var User = $resource('data/main/users.json');
var dataUsers = User.get(function() {
dataUsers.users[0].name = newUser.name;
dataUsers.$save();
});
}
}
function MainCtrl($scope, $rootScope, $log, CRUDservice ) {
var vm = this;
$rootScope.curPath = 'main';
CRUDservice.getData(function(_data) {
vm.users = _data.users;
});
var newUser = {
name: "Valera",
age: 54
}
CRUDservice.saveData(newUser );
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question