mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
refactor: change projection and anchor navigation
This commit is contained in:
23
apps/angular/1-projection/src/app/data-access/city.store.ts
Normal file
23
apps/angular/1-projection/src/app/data-access/city.store.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { City } from '../model/city.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CityStore {
|
||||
private cities = new BehaviorSubject<City[]>([]);
|
||||
cities$ = this.cities.asObservable();
|
||||
|
||||
addAll(cities: City[]) {
|
||||
this.cities.next(cities);
|
||||
}
|
||||
|
||||
addOne(student: City) {
|
||||
this.cities.next([...this.cities.value, student]);
|
||||
}
|
||||
|
||||
deleteOne(id: number) {
|
||||
this.cities.next(this.cities.value.filter((s) => s.id !== id));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user