-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (32 loc) · 963 Bytes
/
index.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
var angular = require('angularjs')
, ffapi = require('ffapi')
, todo = require('todo')
, template = require('./template');
angular.module('todo-list', ['todo', 'ffapi'])
.directive('todoList', function (ffapi) {
return {
scope: {},
replace: true,
restrict: 'A',
template: template,
link: function (scope, element, attrs) {
var name = attrs.todoList;
scope.$watch('todos', function(value) {
scope.$parent[name] = value;
});
scope.$parent.$watch(name, function (value) {
scope.todos = value;
});
scope.removeTodo = function (todo) {
var i = scope.todos.indexOf(todo);
if (i === -1) {
console.warn('Todo not found', todo, scope.todos);
return;
}
scope.todos.splice(i, 1);
ffapi('todos/remove', {id: todo._id});
scope.$parent.$digest();
};
}
};
});