Skip to content
Permalink
Browse files

UPDATE: on double click

  • Loading branch information
amejiarosario committed Aug 7, 2018
1 parent 1a24e3b commit 7f7700b768e212988840d32919db6e28cd8537b0
Showing with 24 additions and 3 deletions.
  1. +8 −3 src/app/todo/todo.component.html
  2. +8 −0 src/app/todo/todo.component.ts
  3. +8 −0 src/app/todo/todo.service.ts
@@ -16,13 +16,18 @@ <h1>Todo</h1>
<input id="toggle-all" class="toggle-all" type="checkbox">

<ul class="todo-list">
<li *ngFor="let todo of todos" [ngClass]="{completed: todo.isDone}" >
<li *ngFor="let todo of todos" [ngClass]="{completed: todo.isDone, editing: todo.editing}" >
<div class="view">
<input class="toggle" type="checkbox" [checked]="todo.isDone">
<label>{{todo.title}}</label>
<label (dblclick)="todo.editing = true">{{todo.title}}</label>
<button class="destroy"></button>
</div>
<input class="edit" value="{{todo.title}}">
<input class="edit"
#updatedTodo
[value]="todo.title"
(blur)="updateTodo(todo, updatedTodo.value)"
(keyup.escape)="todo.editing = false"
(keyup.enter)="updateTodo(todo, updatedTodo.value)">
</li>
</ul>
</section>
@@ -29,6 +29,14 @@ export class TodoComponent implements OnInit {
});
}

updateTodo(todo, newValue) {
todo.title = newValue;
return this.todoService.put(todo).then(() => {
todo.editing = false;
return this.getTodos();
});
}

ngOnInit() {
this.getTodos();
}
@@ -24,4 +24,12 @@ export class TodoService {
resolve(data);
});
}

put(changed) {
return new Promise(resolve => {
const index = TODOS.findIndex(todo => todo === changed);
TODOS[index].title = changed.title;
resolve(changed);
});
}
}

0 comments on commit 7f7700b

Please sign in to comment.
You can’t perform that action at this time.