-
Notifications
You must be signed in to change notification settings - Fork 1
/
loadingTweets.html
70 lines (61 loc) · 1.92 KB
/
loadingTweets.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
<!DOCTYPE HTML>
<html ng-app='myTweets'>
<head>
<title>Hello</title>
</head>
<body>
<div ng-controller="myController">
<label>Total Tweets: {{tweets.length}}</label><br>
<ul>
<li ng-repeat="tweet in tweets | limitTo:currentDisplay">
<button>Edit</button>
<button ng-click="deleteTweet($index)">Delete</button>
{{ tweet.content }}
</li>
</ul>
<button ng-click="loadMoreTweets()">Load More Tweets</button><br><br>
<input type="text" ng-model="newTweet" placeholder="Enter new tweet content"><br>
<!--<button ng-click="addTweet()">Add Tweet</button>-->
<button add-tweet>Add Tweet</button>
</div>
<hr>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.7/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('myTweets', []);
app.controller('myController', function($scope){
$scope.currentDisplay=2;
$scope.tweets = [
{'content':'tweet 1'},
{'content':'tweet 2'}
];
$scope.addTweet = function(){
$scope.tweets.push({'content': $scope.newTweet});
$scope.newTweet = '';
};
$scope.deleteTweet = function(index) {
$scope.tweets.splice(index,1);
};
$scope.loadMoreTweets = function() {
$scope.currentDisplay = $scope.currentDisplay * 2;
};
});
/*
app.directive('delete', function(){
return function(scope, element, attr){
element.bind('click', function(attr){
scope.deleteTweet(attr.deleteTweet);
});
}
});
app.directive('loadMoreTweets', function(){
return {
scope:{},
link: function(scope, element, attr){
scope.currentDisplay = 2*scope.currentDisplay;
}
};
});
*/
</script>
</body>
</html>