var appServices = angular.module('miClaroServices',[]);
appServices.factory('productoServicio', ['$http', '$q',
function($http, $q) {
// interface
var service = {
ListProducto: [],
getListProductos: getListProductos
};
return service;
// implementation
function getListProductos() {
var def = $q.defer();
$http.get('http://172.19.74.235:8909/ProductoServiciosResulFull/service/obtenerServicios/p')
.success(function(data) {
service.ListProducto = data;
def.resolve(data);
})
.error(function() {
def.reject('Failed to get ListProducto');
});
return def.promise;
}
}]);
This is my controller
var appController = angular.module('miClaroController',[]);
appController.controller('miClaroCtr', ['$scope', 'productoServicio',
function($scope, productoServicio) {
var text;
var vm = $scope;
vm.ListProducto = [];
vm.getListProductos = function() {
productoServicio.getListProductos()
.then(function(ListProducto) {
vm.ListProducto = ListProducto;
console.log('Servicio returned to controller.' );
console.log(ListProducto);
},
function(data) {
vm.text = ("Error al consultar los clientes consumer");
console.log(text);
});
};
vm.getListProductos();
}
]);
What I need is that from the services, if $http.get
does not bring anything, follow and consult another and so up to 4 JSON until in some there is data or not.
Please could you help me since I'm new to Angular?