-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.html
66 lines (64 loc) · 1.76 KB
/
post.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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
</head>
<body ng-app='app'>
<div ng-controller='PostsCtrl' class='container'>
<h1>Recent Posts</h1>
<form role='form'>
<div class='form-group'>
<div class='input-group'>
<input ng-model='postBody' class='form-control' />
<span class='input-group-btn'>
<button ng-click='addPost()' class='btn btn-default'>Add Post</button>
</span>
</div>
</div>
</form>
<ul class='list-group'>
<li ng-repeat='post in posts' class='list-group-item'>
<strong>@{{ post.username }}</strong>
<span>{{ post.body }}</span>
</li>
</ul>
</div>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.js'></script>
<script>
// create our app module
var app = angular.module('app', [])
// create the PostsCtrl module
// dependency inject $scope
app.controller("PostsCtrl", function ($scope, $http) {
// the function runs when the "Add Post" button is clicked
$scope.addPost = function () {
// Only add a post if there is a body
if ($scope.postBody) {
// unshift a new post into $scope.posts
$scope.posts.unshift({
username: 'dickeyxxx',
body: $scope.postBody // use the text entered
})
// clear out the input field
$scope.postBody = null
}
}
$http.get("http://localhost:3000/api/post")
.success(function(posts){
$scope.posts = posts
})
// starting data
//$scope.posts = [
//{
// username: 'dickeyxxx',
// body: 'Node rules!'
//},
//{
// username: 'jeffdickey',
// body: 'trying out angular.js...'
//}
//]
})
</script>
</body>
</html>