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 });
}
}
我试图通过调用商店在此处调用storagetestid的状态“ storagetestid”的价值,但要获得“ Storagetestid”的Intial值,我该如何更改状态值并在全球范围内更改状态值。我已经显示了我的商店文件和组件.ts下方
您的问题是将“提供商:[ReservationStore]”从每个组件移动到模块。
@NgModule({
imports: [BrowserModule, FormsModule],
declarations: [
AppComponent,
HelloComponent,
NewBookingModalComponent,
SecondViewComponent,
],
bootstrap: [AppComponent],
providers: [ReservationStore],
})
export class AppModule {}