当我删除父母孩子时没有更新Angular

时间:2018-03-15 09:56:00

标签: angular typescript

我删除了父级,但在UI中仍然是孩子,当我手动重新加载页面时,子项也被删除,当我删除父级时,如何更新或刷新页面,我试过这样但没有任何功能。

deleteProject(project, subproject, position, budget) {
const text = 'Are you sure to delete this project ?';
this.dialog.open(ConfirmationDialogComponent, { data: text, disableClose: true })
  .afterClosed().subscribe(result => {
    if (result) {
      const subIds = this.project.subProjectIds;
      subIds.splice(subIds.indexOf(subproject.id));
      const posIds = this.subproject.positionIds;
      posIds.splice(posIds.indexOf(position.id));
      this.store.dispatch(new DeleteProjectAction(project.id));
    }
  });

}

这是减速器和动作

case DeleteProjectInternalAction.Type:
  return deleteProject(state, action);


function deleteProject(state: BudconState, action: 
DeleteProjectInternalAction): BudconState {
 return {
...state,
projects: state.projects.remove(action.payload)
};

}

export class DeleteProjectInternalAction implements Action {
static readonly Type: string = 'budcon-item:delete-project-internal';
readonly type: string = DeleteProjectInternalAction.Type;

 constructor(public payload?: string) { }
}

export class DeleteProjectAction implements Action {
static readonly Type: string = 'budcon-item:delete-project';
readonly type: string = DeleteProjectAction.Type;

constructor(public payload?: string) { }
}

1 个答案:

答案 0 :(得分:0)

您可以做的是在更改某些内容以加载商店时设置间隔。

  deleteProject(project) {
    const text = 'Are you sure to delete this project ?';
    this.dialog.open(ConfirmationDialogComponent, {width: '30%',
       data: text, disableClose: true })
      .afterClosed().subscribe(result => {
        if (result) {
        this.store.dispatch(new DeleteProjectAction(project.id));
          this.interval = setInterval(() => {  
          //Here define the store to load        
          }, 500);
        } setTimeout(() => {
          clearInterval(this.interval);
        }, 500);
      });
  }