forked from sf-wdi-21/ng-http-resources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (48 loc) · 1.24 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var app = angular.module('wineApp', ['ngRoute']);
// routes
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
// some template & some url
})
.when('/wines/:id', {
// ...
})
.otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}]);
// wine index controller
app.controller('WinesIndexCtrl', ['$scope', '$http', function ($scope, $http) {
var baseUrl = "http://daretodiscover.herokuapp.com/wines";
$scope.wines = [];
$scope.wine = {};
// get all wines on page load
$http.get(baseUrl)
.then(function(response) {
// success cb
}
);
// add a wine on some user action
$scope.createWine = function() {
// success cb
};
// delete a wine on some user action
$scope.deleteWine = function(wine) {
// success cb
};
}]);
// wine show controller
app.controller('WinesShowCtrl', ['$scope', '$http', '$routeParams', function ($scope, $http, $routeParams) {
var baseUrl = "http://daretodiscover.herokuapp.com/wines";
$scope.wine = {};
$http.get(baseUrl + $routeParams.id)
.then(function(response) {
// success cb
}
);
}]);