您好,我试图显示一个模式,当我按下一个按钮,但我得到了以下错误“错误事件:无法分解属性‘事件id’的'this.store.selectSnapshot (...)‘,因为它是未定义的。”可能会发生什么?
此方法应打开模式
handleListar(item: IGeneral) {
this.store.dispatch(new FormActividadSolContainerActions.ListarDatosHistorial({ IdEvento: item.nro }));
const dialogRef = this.dialogService.openXL(ModalHistorialCambiosComponent);
}
这是错误行
private loadGridHistorial = () => {
const { IdEvento: IdEvento } = this.store.selectSnapshot(CONTAINER_STATE_TOKEN);
this.store.dispatch(new ContainerActions.ListarDatosHistorial({ IdEvento }));
}
我的模型
export class FormHistorialModel {
title = 'Detalle Del Historial';
gridHistorial: { loading: boolean; definition: IDataGridDefinition; source: IDataGridSource<any> } = {
loading: false,
definition: {
columns: [
{ label: 'Numero de Evento', field: 'idEvento' },
{ label: 'Nombre de Evento', field: 'nombreEvento' },
{ label: 'Tipo de Evento', field: 'tipoEvento' },
{ label: 'Fecha del Cambio', field: 'fechaCambio' },
{ label: 'Cambio y Motivo', field: 'cambioyMotivo' },
{ label: 'Usuario', field: 'usuario' },
]
},
source: {
items: [],
page: 1,
pageSize: 10,
total: 0
}
};
formType = FormType.CONSULTAR;
IdEvento: number = null;
}
动作
export class ListarDatosHistorial {
static readonly type = '[FORM-ACTIVIDAD-SOL-CONTAINER] ListarDatosHistorial';
constructor(public payload: { IdEvento: number } ) { }
}
状态
listarHistorialSolicitudesBegin = (
ctx: StateContext<FormHistorialModel>
) => {
const state = ctx.getState();
ctx.patchState({
gridHistorial: {
...state.gridHistorial,
loading: true
},
});
}
listarHistorialSolicitudesSuccess = (
ctx: StateContext<FormHistorialModel>
) => (items: any[]) => {
const state = ctx.getState();
ctx.patchState({
gridHistorial: {
...state.gridHistorial,
loading: false,
source: {
...state.gridHistorial.source,
items,
pageSize: items.length,
total: items.length,
}
},
});
}
listarHistorialSolicitudesError = (
ctx: StateContext<FormHistorialModel>
) => (error) => {
const state = ctx.getState();
ctx.patchState({
gridHistorial: {
...state.gridHistorial,
loading: false
},
});
}
@Action(ContainerActions.ListarDatosHistorial)
asynclistarHistorial(
ctx: StateContext<FormHistorialModel>,
{ payload }: ContainerActions.ListarDatosHistorial
) {
this.listarHistorialSolicitudesBegin(ctx);
return this.historialService.ListarHistorial(payload.IdEvento).pipe(
tap(response => {
this.listarHistorialSolicitudesSuccess(ctx)(
response.data || []
);
}),
catchError(err => {
this.listarHistorialSolicitudesError(ctx)(err);
return throwError(err);
})
);
}
服务
发布于 2021-06-18 22:37:42
我将从输入一个断点/调试器语句开始,看看快照返回的是什么:
private loadGridHistorial = () => {
const state = this.store.selectSnapshot(CONTAINER_STATE_TOKEN);
debugger; // now inspect the state variable
this.store.dispatch(new ContainerActions.ListarDatosHistorial({ IdEvento }));
}
如果它不起作用,那么尝试将状态标记更改为状态类名this.store.selectSnapshot(ContainerState);
发布于 2021-06-19 02:29:20
我不是100%确定,但我相信selectSnapshot
只会返回整个状态对象的回调。然后,您需要指向您想要的状态片段,以便获得您正在查找的值。
来自ngxs.io/concepts/select#snapshot-selects的示例
@Injectable()
export class JWTInterceptor implements HttpInterceptor {
constructor(private store: Store) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const token = this.store.selectSnapshot<string>((state: AppState) => state.auth.token);
req = req.clone({
setHeaders: {
Authorization: `Bearer ${token}`
}
});
return next.handle(req);
}
}
https://stackoverflow.com/questions/68036103
复制相似问题