Skip to content

Commit

Permalink
Added Article Delete Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Amos Haviv authored and Amos Haviv committed Nov 22, 2013
1 parent 8d1b130 commit eeb5423
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
14 changes: 10 additions & 4 deletions public/js/controllers/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ angular.module('mean.articles').controller('ArticlesController', ['$scope', '$ro
};

$scope.remove = function(article) {
article.$remove();
if (article) {
article.$remove();

for (var i in $scope.articles) {
if ($scope.articles[i] == article) {
$scope.articles.splice(i, 1);
for (var i in $scope.articles) {
if ($scope.articles[i] == article) {
$scope.articles.splice(i, 1);
}
}
}
else {
$scope.article.$remove();
$location.path('articles');
}
};

$scope.update = function() {
Expand Down
18 changes: 13 additions & 5 deletions public/views/articles/view.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<section data-ng-controller="ArticlesController" data-ng-init="findOne()">
<span>{{article.created | date:'medium'}}</span> /
<span>{{article.user.name}}</span>
<h2>{{article.title}} <a data-ng-show="global.user._id == article.user._id" href="/#!/articles/{{article._id}}/edit">edit</a></h2>
<div>{{article.content}}</div>
</section>
<span>{{article.created | date:'medium'}}</span>/
<span>{{article.user.name}}</span>
<h2>{{article.title}}</h2>
<div data-ng-show="global.user._id == article.user._id">
<a class="btn" href="/#!/articles/{{article._id}}/edit">
<i class="icon-edit"></i>
</a>
<a class="btn" data-ng-click="remove();">
<i class="icon-trash"></i>
</a>
</div>
<div>{{article.content}}</div>
</section>

0 comments on commit eeb5423

Please sign in to comment.