Skip to content

Instantly share code, notes, and snippets.

@brunokrebs
Created March 2, 2017 14:36
Show Gist options
  • Save brunokrebs/d40388719f14c5d175df68f1cb62053c to your computer and use it in GitHub Desktop.
Save brunokrebs/d40388719f14c5d175df68f1cb62053c to your computer and use it in GitHub Desktop.
// ... 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