modif task service
This commit is contained in:
parent
587b979ff2
commit
5b2f25b6bd
1 changed files with 7 additions and 2 deletions
|
|
@ -2,6 +2,11 @@ import { Injectable } from '@angular/core';
|
|||
import { BehaviorSubject, of } from 'rxjs';
|
||||
import { delay } from 'rxjs/operators';
|
||||
|
||||
export interface TaskItem {
|
||||
id: number;
|
||||
title: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
|
|
@ -17,11 +22,11 @@ export class TaskService {
|
|||
return of(this.tasks).pipe(delay(1000));
|
||||
}
|
||||
|
||||
private tasksSubject = new BehaviorSubject(this.tasks);
|
||||
private tasksSubject = new BehaviorSubject<TaskItem[]>(this.tasks);
|
||||
tasks$ = this.tasksSubject.asObservable();
|
||||
|
||||
addTask(title: string) {
|
||||
const newTask = { id: this.nextId++, title: title.trim() };
|
||||
const newTask: TaskItem = { id: this.nextId++, title: title.trim() };
|
||||
this.tasks.push(newTask);
|
||||
this.tasksSubject.next([...this.tasks]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue