首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法对'this.store.selectSnapshot‘的属性'IdEvento’进行结构分析

无法对'this.store.selectSnapshot‘的属性'IdEvento’进行结构分析
EN

Stack Overflow用户
提问于 2021-06-18 21:33:25
回答 2查看 76关注 0票数 1

您好,我试图显示一个模式,当我按下一个按钮,但我得到了以下错误“错误事件:无法分解属性‘事件id’的'this.store.selectSnapshot (...)‘,因为它是未定义的。”可能会发生什么?

此方法应打开模式

代码语言:javascript
运行
复制
  handleListar(item: IGeneral) {
    this.store.dispatch(new FormActividadSolContainerActions.ListarDatosHistorial({ IdEvento: item.nro }));
    const dialogRef = this.dialogService.openXL(ModalHistorialCambiosComponent);    
  }

这是错误行

代码语言:javascript
运行
复制
  private loadGridHistorial = () => {
    const { IdEvento: IdEvento } = this.store.selectSnapshot(CONTAINER_STATE_TOKEN);
    this.store.dispatch(new ContainerActions.ListarDatosHistorial({ IdEvento }));
  }

我的模型

代码语言:javascript
运行
复制
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;    
}

动作

代码语言:javascript
运行
复制
  export class ListarDatosHistorial {
    static readonly type = '[FORM-ACTIVIDAD-SOL-CONTAINER] ListarDatosHistorial';
    constructor(public payload: { IdEvento: number }  ) { }
  }

状态

代码语言:javascript
运行
复制
  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);
      })
    );
  }

服务

EN

回答 2

Stack Overflow用户

发布于 2021-06-18 22:37:42

我将从输入一个断点/调试器语句开始,看看快照返回的是什么:

代码语言:javascript
运行
复制
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);

票数 0
EN

Stack Overflow用户

发布于 2021-06-19 02:29:20

我不是100%确定,但我相信selectSnapshot只会返回整个状态对象的回调。然后,您需要指向您想要的状态片段,以便获得您正在查找的值。

来自ngxs.io/concepts/select#snapshot-selects的示例

代码语言:javascript
运行
复制
@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);
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68036103

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档