Not the right approach to implementation, you need to use the service, not the best implementation, but as an example, my service will come down, but in general I am doing now through ngresource. In the Controller, it remains only to check whether the ID came in, if there is, then we take 1 record from Projects.items, if there is no data in the items, try downloading them from the server. Post takes me away from me because I still pass the parameters for cropping images, in your case, get will be enough.
questServices.factory('Projects', ['$http', '$timeout', 'Upload', function ($http, $timeout, Upload) { var service = function (editor) { this.items = []; this.busy = false; this.after = ''; this.page = ''; this.end = false; this.new_project = {}; this.getClass = 'btn-default'; this.setdelete = null; }; service.prototype.save = function () { if (this.busy) return; this.busy = true; var file = this.new_project.image; file.upload = Upload.upload({ url: '/resource/addproject', data: {file: file, project: JSON.stringify(this.new_project)}, }); file.upload.then(function (response) { this.busy = false; console.log(response.data); this.new_project = {}; this.getClass = 'btn-success'; this.load(); $timeout(function () { this.getClass = 'btn-default'; this.busy = false; }.bind(this), 2000); }.bind(this), function (response) { //this.busy = false; //console.log('test'); //console.log(response.data); }, function (evt) { // Math.min is to fix IE which reports 200% sometimes file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); console.log(file.progress); }); } service.prototype.load = function (params, callback) { if (this.busy) return; this.busy = true; var url = "resource/projects"; $http.post(url, params). then(function (response) { console.log(response.data); this.items = response.data.projects; this.busy = false; $timeout(function () { if (typeof callback == 'function') callback(); }.bind(this), 1000); }.bind(this), function (response) { console.log(response); }); }; service.prototype.delete = function () { if (this.busy) return; this.busy = true; var url = "resource/deleteproject/" + this.setdelete.id; $http.get(url). success(function (data, status, headers, config) { console.log(data); angular.forEach(this.items, function (item, key) { if (item.id == this.setdelete.id) { this.items.splice(key, 1); } }.bind(this)); this.setdelete = null; this.busy = false; }.bind(this)). error(function (data, status, headers, config) { }); }; service.prototype.update = function () { if (this.busy) return; this.busy = true; var url = "resource/updateproject"; var file = this.new_project.image; if (file) { console.log('Отправил через файл'); file.upload = Upload.upload({ url: url, data: {file: file, project: JSON.stringify(this.new_project)}, }); file.upload.then(function (response) { this.busy = false; console.log(response.data); this.getClass = 'btn-success'; this.load(); $timeout(function () { this.getClass = 'btn-default'; this.new_project = {}; this.busy = false; }.bind(this), 2000); }.bind(this), function (response) { //this.busy = false; //console.log('test'); //console.log(response.data); }, function (evt) { // Math.min is to fix IE which reports 200% sometimes file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); console.log(file.progress); }); } else { $http.post(url, {project: JSON.stringify(this.new_project)}). then(function (response) { console.log(response); this.getClass = 'btn-success'; $timeout(function () { this.getClass = 'btn-default'; this.busy = false; }.bind(this), 2000); }.bind(this), function (response) { console.log(response); }); } }; return service; } ]);