Skip to content
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

Commit eeb5423

Browse files
Amos HavivAmos Haviv
authored andcommitted
Added Article Delete Support
1 parent 8d1b130 commit eeb5423

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

public/js/controllers/articles.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ angular.module('mean.articles').controller('ArticlesController', ['$scope', '$ro
1515
};
1616

1717
$scope.remove = function(article) {
18-
article.$remove();
18+
if (article) {
19+
article.$remove();
1920

20-
for (var i in $scope.articles) {
21-
if ($scope.articles[i] == article) {
22-
$scope.articles.splice(i, 1);
21+
for (var i in $scope.articles) {
22+
if ($scope.articles[i] == article) {
23+
$scope.articles.splice(i, 1);
24+
}
2325
}
2426
}
27+
else {
28+
$scope.article.$remove();
29+
$location.path('articles');
30+
}
2531
};
2632

2733
$scope.update = function() {

public/views/articles/view.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
<section data-ng-controller="ArticlesController" data-ng-init="findOne()">
2-
<span>{{article.created | date:'medium'}}</span> /
3-
<span>{{article.user.name}}</span>
4-
<h2>{{article.title}} <a data-ng-show="global.user._id == article.user._id" href="/#!/articles/{{article._id}}/edit">edit</a></h2>
5-
<div>{{article.content}}</div>
6-
</section>
2+
<span>{{article.created | date:'medium'}}</span>/
3+
<span>{{article.user.name}}</span>
4+
<h2>{{article.title}}</h2>
5+
<div data-ng-show="global.user._id == article.user._id">
6+
<a class="btn" href="/#!/articles/{{article._id}}/edit">
7+
<i class="icon-edit"></i>
8+
</a>
9+
<a class="btn" data-ng-click="remove();">
10+
<i class="icon-trash"></i>
11+
</a>
12+
</div>
13+
<div>{{article.content}}</div>
14+
</section>

0 commit comments

Comments
 (0)