Created
November 1, 2015 16:18
-
-
Save suissa/82c42d6c9731937a879f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('myApp.Beers', ['ngRoute', 'BeerServiceModule']) | |
.config(['$routeProvider', function($routeProvider) { | |
$routeProvider | |
.when('/beers', { | |
templateUrl: 'modules/beers/list.html', | |
controller: 'BeersList' | |
}) | |
.when('/beers/create', { | |
templateUrl: 'modules/beers/create.html', | |
controller: 'BeersCreate' | |
}) | |
.when('/beers/:id', { | |
templateUrl: 'modules/beers/get.html', | |
controller: 'BeersGet' | |
}) | |
; | |
}]) | |
.controller('BeersList', BeersList) | |
.controller('BeersGet', BeersGet) | |
.controller('BeersCreate', BeersCreate); | |
BeersList['$inject'] = ['$scope', 'BeerService']; | |
BeersCreate['$inject'] = ['$scope', 'BeerService']; | |
BeersGet['$inject'] = ['$scope', 'BeerService', '$routeParams']; | |
function BeersList($scope, BeerService) { | |
$scope.reverse = true; | |
$scope.predicate = 'name'; | |
$scope.ordenar = function(predicado){ | |
$scope.reverse = !$scope.reverse; | |
$scope.predicate = predicado; | |
} | |
function success(result) { | |
console.log(result); | |
$scope.beers = result.data | |
}; | |
function error(err) { | |
console.log(err); | |
}; | |
BeerService.find().then(success, error); | |
} | |
function BeersGet($scope, BeerService, $routeParams) { | |
var id = $routeParams.id; | |
function success(result) { | |
console.log(result); | |
$scope.beer = result.data | |
}; | |
function error(err) { | |
console.log(err); | |
}; | |
BeerService.get(id).then(success, error); | |
} | |
function BeersCreate($scope, BeerService) { | |
function success(result) { | |
console.log(result); | |
$scope.beers = result.data | |
}; | |
function error(err) { | |
console.log(err); | |
}; | |
function create(beer) { | |
BeerService.create(beer).then(success, error); | |
} | |
$scope.create = create; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment