You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

34 lines
880 B

import { Component, OnInit } from '@angular/core';
import { TaskService } from '../../services/task.service';
import { Task } from '../../Task';
@Component({
selector: 'app-tasks',
templateUrl: './tasks.component.html',
styleUrls: ['./tasks.component.css']
})
export class TasksComponent implements OnInit {
tasks: Task[] = [];
constructor(private taskService: TaskService) {
}
ngOnInit(): void {
this.taskService.getTasks().subscribe((tasks) => this.tasks = tasks);
}
deleteTask(task:Task) {
this.taskService.deleteTask(task).subscribe(() => this.tasks = this.tasks.filter(t => t.id !== task.id));
}
toggleReminder(task:Task) {
task.reminder = !task.reminder;
this.taskService.updateTaskReminder(task).subscribe();
}
addTask(task:Task) {
this.taskService.addTask(task).subscribe((task)=>(this.tasks.push(task)))
}
}