Imported MEAN stack files
This commit is contained in:
52
public/js/controllers/articles.js
Executable file
52
public/js/controllers/articles.js
Executable file
@@ -0,0 +1,52 @@
|
||||
angular.module('mean.articles').controller('ArticlesController', ['$scope', '$routeParams', '$location', 'Global', 'Articles', function ($scope, $routeParams, $location, Global, Articles) {
|
||||
$scope.global = Global;
|
||||
|
||||
$scope.create = function() {
|
||||
var article = new Articles({
|
||||
title: this.title,
|
||||
content: this.content
|
||||
});
|
||||
article.$save(function(response) {
|
||||
$location.path("articles/" + response._id);
|
||||
});
|
||||
|
||||
this.title = "";
|
||||
this.content = "";
|
||||
};
|
||||
|
||||
$scope.remove = function(article) {
|
||||
article.$remove();
|
||||
|
||||
for (var i in $scope.articles) {
|
||||
if ($scope.articles[i] == article) {
|
||||
$scope.articles.splice(i, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.update = function() {
|
||||
var article = $scope.article;
|
||||
if (!article.updated) {
|
||||
article.updated = [];
|
||||
}
|
||||
article.updated.push(new Date().getTime());
|
||||
|
||||
article.$update(function() {
|
||||
$location.path('articles/' + article._id);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.find = function() {
|
||||
Articles.query(function(articles) {
|
||||
$scope.articles = articles;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.findOne = function() {
|
||||
Articles.get({
|
||||
articleId: $routeParams.articleId
|
||||
}, function(article) {
|
||||
$scope.article = article;
|
||||
});
|
||||
};
|
||||
}]);
|
Reference in New Issue
Block a user