mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
24 lines
572 B
TypeScript
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));
|
|
}
|
|
}
|