Skip to content

Instantly share code, notes, and snippets.

@washingtonsoares
Created March 21, 2016 20:06
Show Gist options
  • Save washingtonsoares/2131c3f3a2f1da21e516 to your computer and use it in GitHub Desktop.
Save washingtonsoares/2131c3f3a2f1da21e516 to your computer and use it in GitHub Desktop.
angular
.module('ionicApp.state.CampaingCategoryController', [])
.controller('CampaingCategoryController', ['$scope','CampaingCategoryFactory', function ($scope, CampaingCategoryFactory) {
console.log('CampaingCategoriesController loaded');
// CampaingCategoryFactory.hello();
// CampaingCategoryFactory.categories();
// CampaingCategoryFactory.category();
$scope.categories = CampaingCategoryFactory.categories().then(function(data){
$scope.dados = data;
},function(){
//erro ao buscar os dados
};
}]);
angular
.module('ionicApp.state.CampaingCategoryFactory', [])
.factory('CampaingCategoryFactory', function($http, $q){
var sayHello = function() {
console.log('hello from factory');
};
var getCampaingCategories = function() {
var deferral = $q.defer();
$http({
method: 'GET',
url: 'http://0.0.0.0:3000/campaing_categories'
}).success(function(data){
deferral.resolve(data);
}).error(function(){
deferral.reject();
});
return deferral.promise;
};
var getCategory = function() {
};
return {
categories: getCampaingCategories,
category: getCategory,
hello: sayHello
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment