forked from ttc/micro-frontend
-interface
-service -เพิ่มเทคนิค การส่ง ผ่านข้อมูล
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { IDropAct } from '../../interfaces/dashboard.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DashboardStateService {
|
||||
// ประกาศ BehaviorSubject ด้วย Interface
|
||||
private productState = new BehaviorSubject<IDropAct | null>(null);
|
||||
|
||||
// ส่ง Observable ไปให้ components subscribe
|
||||
getStateResult(): Observable<IDropAct | null> {
|
||||
return this.productState.asObservable();
|
||||
}
|
||||
|
||||
// เซ็ท state
|
||||
setStateResult(product: IDropAct): void {
|
||||
this.productState.next(product);
|
||||
}
|
||||
|
||||
// เคลียร์ state
|
||||
clearState(): void {
|
||||
this.productState.next(null);
|
||||
}
|
||||
|
||||
// ดึงค่า current state (ไม่ใช่ observable)
|
||||
// getCurrentState(): IDropAct | null {
|
||||
// return this.productState.value;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user