Created
March 2, 2017 14:36
-
-
Save brunokrebs/d40388719f14c5d175df68f1cb62053c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... other imports | |
import { EventEmitter, Output } from '@angular/core'; | |
// ... component definition | |
export class TaskListComponent implements OnInit { | |
@Output() | |
startAjaxRequest = new EventEmitter<void>(); | |
@Output() | |
completeAjaxRequest = new EventEmitter<void>(); | |
// ... properties, constructor and ngOnInit definitions | |
private loadTasks() { | |
this.startAjaxRequest.emit(); | |
this.taskListService.loadTasks$().subscribe( | |
response => this.tasks = response.json(), | |
error => console.log(error), | |
() => this.completeAjaxRequest.emit() | |
); | |
} | |
taskAddedHandler(task) { | |
this.startAjaxRequest.emit(); | |
this.taskListService.addTask$(task).subscribe( | |
response => this.loadTasks(), | |
error => console.log() | |
); | |
} | |
deleteTask(task) { | |
this.startAjaxRequest.emit(); | |
this.taskListService.deleteTask$(task).subscribe( | |
response => this.loadTasks(), | |
error => console.log() | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment