(function(){
'use strict';
angular
.module('service.dataByCommands',[])
.factory('serviceDataByCommands', serviceDataByCommands);
function serviceDataByCommands($http) {
var _vm;
return {
name: 'Commands Service',
add: function (vm) {
_vm = vm;
$http.post('addData.php',{genCommand:vm.newGenerationCommand, description:vm.newDescription})
.then(function(response) {
RETURN ('SUCCESS');
})
.catch(function(error) {
console.log(error);
});
},
get: function (callback) {
$http.get('getData.php')
.then(function(response) {
callback(response.data);
},
function(error) {
console.log(error);
});
}
}
}
})();
var vm = this;
.....
serviceDataByCommands.get(function(data){
vm.lists = data;
});
vm.addCommand = function() {
var status = serviceDataByCommands.add(vm);
if (status === 'success'){
vm.notify('Данные успешно добавленны!');
vm.lists.push({
id: response.data.id,
command: response.data.command,
description: response.data.description,
completed: response.data.completed
});
}
};
.....
function serviceDataByCommands($http) {
return {
name: 'Commands Service',
add: function (vm) {
return $http.post('addData.php',{genCommand:vm.newGenerationCommand, description:vm.newDescription});
},
...........................
return $http.get('getData.php')
.then(function(response) {
return response.data;
},
function(error) {
console.log(error);
});
var status = serviceDataByCommands.add(vm);
status.then(function(response){
if (response=== 'success'){
vm.notify('Данные успешно добавленны!');
vm.lists.push({
id: response.data.id,
command: response.data.command,
description: response.data.description,
completed: response.data.completed
});
}
})