首页 文章

在Angular2 rc5中使用ng2-bootstrap模态的Quirk

提问于
浏览
1

我一直在使用Angular2构建日历应用程序,最近我升级到了rc5 . 我的日历允许用户通过使用详细模式创建/编辑约会详细信息,然后显示更改并提示用户确认另一个模式中的更改 . 它还允许用户拖放事件并相应地计算新的日期/时间 . 该应用程序在升级到rc5之前工作正常 . 自升级以来,当用户将事件拖动到新时间时,确认模式将打开并显示上次更改,并且仅当用户在模式内部单击时才会更新以反映新更改 .

预期流程:拖放 - >更新值 - >打开显示以显示新的更改

当前流程:拖放 - >打开显示 - >(单击模态时)更改值以反映新的事件时间

我没有更改我的代码,所以我怀疑rc5处理模式的方式有一些变化 . 我正在使用“ng2-bootstrap”,细节编辑的流程仍然正常 .

viewProviders:[BS_VIEW_PROVIDERS]指令:[MODAL_DIRECTIVES]

拖放处理程序:

confirmEvent(response) {
    this.changeEvent = this.calendarService.getEvent(this.events, response.existingEvent);
    this.event = response.newEvent;
    this.confirmAction = response.action;
    this.eventService.getEventParticipants(this.changeEvent);
    this.appointmentConfirmComponent.show();
  }

细节响应处理程序

handleDetailsResponse(response) {
    this.changeEvent = this.calendarService.getEvent(this.events, response.event);
    this.eventService.getEventParticipants(this.changeEvent);
    this.event = response.event;
    this.appointmentDetailComponent.hide();

    switch (response.action) {
      case 'delete':
        if(this.changeEvent.id && this.changeEvent.id !== '') {
          this.confirmAction = 'delete';
          this.appointmentConfirmComponent.show();
        }
        break;
      case 'save':
        if (this.event.id && this.event.id !== '') {
          this.confirmAction = 'update';
        } else {
          this.confirmAction = 'save';
        }
        this.appointmentConfirmComponent.show();
        break;
      default:
        this.confirmAction = 'ERROR';
        this.updateSources();
        break;
    }
  }

如果需要,我可以强制模态上的事件欺骗它进行更新,但这似乎很草率 . 是否有一种干净的方法来强制模态更新?

calendar.component.html

<div class="row" style="margin-top: 1rem;">
    <div class="card col-xs-8 col-xs-offset-1 flex" style="padding-top: 1rem;">
        <calendar-body class="flex-content"
                [calendarEvents]='events' 
                (editEvent)='editEvent($event)' (confirmEvent)='confirmEvent($event)'>
        </calendar-body>
    </div>

    <appointment-detail [event]="event" (submitDetails)="handleDetailsResponse($event)"></appointment-detail>
    <appointment-confirm [existingEvent]="changeEvent" [newEvent]="event" [action]="confirmAction" (submitConfirmation)="handleConfirmResponse($event)"></appointment-confirm>
</div>

1 回答

  • 0

    我解决问题的方法是将ChangeDetectorRef拉入父组件,并在拖放事件触发后调用this.cd.detectChanges() . 这会导致虚拟DOM意识到事件具有新值并相应地更新显示 .

相关问题