modif task service

This commit is contained in:
ExostFlash 2025-11-26 16:12:59 +01:00
parent 587b979ff2
commit 5b2f25b6bd

View file

@ -2,6 +2,11 @@ import { Injectable } from '@angular/core';
import { BehaviorSubject, of } from 'rxjs'; import { BehaviorSubject, of } from 'rxjs';
import { delay } from 'rxjs/operators'; import { delay } from 'rxjs/operators';
export interface TaskItem {
id: number;
title: string;
}
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
@ -17,11 +22,11 @@ export class TaskService {
return of(this.tasks).pipe(delay(1000)); return of(this.tasks).pipe(delay(1000));
} }
private tasksSubject = new BehaviorSubject(this.tasks); private tasksSubject = new BehaviorSubject<TaskItem[]>(this.tasks);
tasks$ = this.tasksSubject.asObservable(); tasks$ = this.tasksSubject.asObservable();
addTask(title: string) { 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.tasks.push(newTask);
this.tasksSubject.next([...this.tasks]); this.tasksSubject.next([...this.tasks]);
} }