-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-todos-angular.js
41 lines (32 loc) · 1 KB
/
simple-todos-angular.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
Tasks = new Mongo.Collection('tasks');
if (Meteor.isClient) {
// counter starts at 0
Session.setDefault('counter', 0);
angular.module('simple-todos',['angular-meteor']);
angular.module('simple-todos').controller('TodosListCtrl', ['$scope', '$meteor',
function ($scope, $meteor) {
$scope.tasks = $meteor.collection(function() {
return Tasks.find($scope.getReactively('query'), {sort: {createdAt: -1}})
});
$scope.addTask = function (newTask) {
$scope.tasks.push( {
text: newTask,
createdAt: new Date() }
);
};
$scope.$watch('hideCompleted', function() {
if ($scope.hideCompleted)
$scope.query = {checked: {$ne: true}};
else
$scope.query = {};
});
$scope.incompleteCount = function () {
return Tasks.find({ checked: {$ne: true} }).count();
};
}]);
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}