forked from travis4all/baucis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathangular-example-restangular.html
42 lines (38 loc) · 1.35 KB
/
angular-example-restangular.html
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
<html ng-app="angularexample">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<script src="http://cdn.jsdelivr.net/restangular/1.1.3/restangular.min.js"></script>
<script src="http://cdn.jsdelivr.net/underscorejs/1.5.1/underscore-min.js"></script>
<script type="text/javascript">
var angularExample =angular.module('angularexample',["restangular"])
angularExample.config(["RestangularProvider",function(RestangularProvider){
RestangularProvider.setRestangularFields({
id: "_id"
});
}]);
angularExample.controller("MainCtrl",["Restangular","$scope",function(Restangular,$scope){
var resource = Restangular.all('api/vegetables')
resource.getList().then(function(vegetables){
$scope.vegetables = vegetables;
});
$scope.add = function() {
resource.post($scope.newVegetable).then(function(newResource){
$scope.vegetables.push(newResource);
})
}
}])
</script>
</head>
<body>
<div ng-controller="MainCtrl">
<div ng-repeat="vegetable in vegetables">
name is: {{vegetable.name}}.<br/>
change name:<input type="text" ng-model="vegetable.name"/><button type="submit" ng-click="vegetable.put()">update</button>
</div>
<div>
add new: <br/>
<input type="text" ng-model="newVegetable.name"/><button type="submit" ng-click="add()">add</button>
</div>
</div>
</body>
</html>