import { IStorageRoom } from '../models/storageRoom/storageRoom';
import { Injectable } from '@angular/core';
import { ComponentStore } from '@ngrx/component-store';
import { Observable } from 'rxjs';
export interface AddReservationState {
StorageRooms: IStorageRoom[];
storagetestId: any;
}
@Injectable()
export class ReservationStore extends ComponentStore<AddReservationState> {
constructor() {
super({
StorageRooms: [],
storagetestId: 'initial value',
});
}
StorageRooms$: Observable<IStorageRoom[]> = this.select(
(state) => state.StorageRooms
);
storagetestId$: Observable<any> = this.select((state) => state.storagetestId);
}
import { ReservationStore } from 'src/app/Store/AddReservation.store';
@Component({
selector: 'app-new-booking-modal',
templateUrl: './new-booking-modal.page.html',
styleUrls: ['./new-booking-modal.page.scss'],
providers: [ReservationStore],
})
export class NewBookingModalPage implements OnInit {
storagetestId$ = this.reservationStore.storagetestId$;
constructor(private reservationStore: ReservationStore) {}
ngOnInit() {
this.bookingFun(' changed value');
}
bookingFun(storagetestId) {
this.reservationStore.patchState({ storagetestId });
}
}
我试图通过调用store来获取其他组件中状态"storagetestId"的更改值,但在那里获取了"storagetestId"的初始值,如何才能全局更改状态值并获取更改值.我已经展示了我的存储文件和组件.ts.