-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
85 lines (73 loc) · 2.7 KB
/
index.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Sample Angular Scaffold project</title>
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-model/src/angular-model.js"></script>
<script src="angular-scaffold.js"></script>
<!-- Define where to get the posts from. Will default to /posts if omitted. -->
<link rel="resource" name="posts" href="/api/posts">
</head>
<body>
<div ng-controller="postsController">
<h1>posts</h1>
<ul>
<li ng-repeat="item in posts.items track by item._id">
{{ item.name }} <button ng-click="$ui.show($index)">Show</button> <button ng-click="$ui.delete($index)">Delete</button>
<div ng-show="$ui.showing == $index">{{ item.body }}</div>
</li>
</ul>
<form>
New post
<input ng-model="newPost._id" placeholder="id">
<input ng-model="newPost.name" placeholder="name">
<input ng-model="newPost.body" placeholder="body text">
<button ng-click="$ui.save()">Save</button>
</form>
</div>
<script>
(function() {
'use strict';
// Define a namespace for myApp and state dependencies
angular.module('myApp', ['ur.model', 'ur.scaffold'])
// configure an angular-model instance that we can scaffold
.config(function(modelProvider) {
modelProvider.model('posts', {});
})
// define a controller which uses the scaffold
.controller('postsController', function($scope, scaffold, model) {
angular.extend($scope, {
// a blank post used for adding new posts to the scaffold
newPost: model('posts').create({}),
// the scaffolded object
posts: scaffold('posts', {}),
// User interface functions to manipulate the posts scaffold
$ui: {
showing: -1,
show: function(index) {
$scope.$ui.showing = index;
},
resetShowing: function() {
$scope.$ui.showing = -1;
},
delete: function(index) {
$scope.$ui.resetShowing();
$scope.posts.items[index].$delete().then(function() {
return $scope.posts.items.splice(index, 1);
});
},
save: function() {
$scope.$ui.resetShowing();
$scope.newPost.$save().then(function() {
// refresh the scaffold
$scope.posts.refresh();
$scope.newPost = model('posts').create({});
});
}
}
});
});
})();
</script>
</body>
</html>