Skip to content
Permalink
Browse files

UPDATE: on double click

  • Loading branch information
amejiarosario committed Nov 7, 2019
1 parent dd432b4 commit f1270ef51db43d6640df4b327677cd8e069fbcdf
Showing with 25 additions and 3 deletions.
  1. +9 −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
@@ -13,14 +13,20 @@ <h1>Todo</h1>
<section class="main">

<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();
}
@@ -25,4 +25,12 @@ export class TodoService {
});
}

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

}

0 comments on commit f1270ef

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