Skip to content

Commit feb7399

Browse files
committed
add view comments
1 parent afe8983 commit feb7399

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ app.controller("RedditClone", function($scope) {
4747
$scope.post.comments = [];
4848
$scope.post.comment = {};
4949
$scope.commentForm = false;
50+
$scope.commentsView = false;
5051
$scope.sortChoice = '-votes';
5152

5253
$scope.showPostForm = function() {
@@ -71,6 +72,11 @@ app.controller("RedditClone", function($scope) {
7172
$scope.addComment = function(post) {
7273
post.comments.push(this.comment);
7374
this.comment = {};
75+
this.commentForm = false;
76+
}
77+
78+
$scope.showComments = function(post) {
79+
this.commentsView = true;
7480
}
7581

7682
})

index.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
<meta http-equiv="x-ua-compatible" content="ie=edge">
88
<title>Angular Part 7</title>
99
<meta name="description" content="Galvanize Full Stack self-paced Angular. Part 7: Angular Reddit Clone">
10-
<!-- Latest compiled and minified CSS -->
1110
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
12-
<!-- Optional theme -->
1311
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
1412
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.4/lumen/bootstrap.min.css">
1513
<link rel="stylesheet" href="style.css">
@@ -81,10 +79,12 @@
8179
<p id="description">{{post.desc}}</p>
8280
</div>
8381
<div class="row">
84-
<p><span class="glyphicon glyphicon-calendar"></span><time title="{{ post.date | amDateFormat: 'dddd, MMMM Do YYYY, h:mm a' }}">{{post.date | amCalendar}}</time> | <span class="glyphicon glyphicon-comment"></span>
85-
<ng-pluralize count="post.comments.length" when="{
82+
<p><span class="glyphicon glyphicon-calendar"> </span><time title="{{ post.date | amDateFormat: 'dddd, MMMM Do YYYY, h:mm a' }}">{{post.date | amCalendar}}</time> | <span class="glyphicon glyphicon-comment"></span> <span ng-click="showComments(post); $event.stopPropagation()"><ng-pluralize count="post.comments.length" when="{
8683
'1': '{{post.comments.length}} comment',
87-
'other': '{{post.comments.length}} comments'}"></ng-pluralize> | <span class="glyphicon glyphicon-pencil"></span><span ng-click="showCommentForm(post); $event.stopPropagation()">Add Comment</span></p>
84+
'other': '{{post.comments.length}} comments'}"></ng-pluralize></span> | <span class="glyphicon glyphicon-pencil"></span><span ng-click="showCommentForm(post); $event.stopPropagation()">Add Comment</span></p>
85+
<div ng-show="commentsView" ng-repeat="comment in post.comments">
86+
<p><strong>{{comment.author}}</strong> - {{comment.text}}</p>
87+
</div>
8888
<form ng-show="commentForm">
8989
<div>
9090
<label for="author">Author</label>
@@ -93,6 +93,7 @@
9393
<input type="text" ng-model="comment.text" name="text" placeholder="Comment">
9494
<button class="btn btn-default" type="submit" ng-click="addComment(post); $event.stopPropogation()">Add Comment</button>
9595
</div>
96+
</form>
9697
</div>
9798
</div>
9899
<div class="clearfix"></div>

0 commit comments

Comments
 (0)