-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy patharticles.js
48 lines (40 loc) · 1.04 KB
/
articles.js
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
function ArticlesController($scope, $routeParams, $location, Articles) {
$scope.articles = [];
$scope.article = {};
$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 (query) {
Articles.query(query, function (articles) {
$scope.articles = articles;
});
};
$scope.findOne = function () {
Articles.get({ articleId: $routeParams.articleId }, function (article) {
$scope.article = article;
});
};
}