Files
angular-challenges/apps/projection/src/app/data-access/student.store.ts
2022-11-03 15:37:58 +01:00

24 lines
572 B
TypeScript

import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { Student } from '../model/student.model';
@Injectable({
providedIn: 'root',
})
export class StudentStore {
private students = new BehaviorSubject<Student[]>([]);
students$ = this.students.asObservable();
addAll(students: Student[]) {
this.students.next(students);
}
addOne(student: Student) {
this.students.next([...this.students.value, student]);
}
deleteOne(id: number) {
this.students.next(this.students.value.filter((s) => s.id !== id));
}
}