角度组件无法刷新用户界面

时间:2020-07-22 17:35:15

标签: javascript angular

我具有以下代码结构:

  • component1.ts
<div class="column-3">
            <div class="fr">
              <a
                class="a-notification"
                [class.a-not-notification]="changeColorClassWhenNotValues()"
                (click)="openHeldCommissionModal()"
                >Held Commissions
                <div
                  class="commission-counter"
                  [class.commission-counter-blue]="changeColorClassWhenNotValues()"
                >
                  {{ heldDetailsReportCount }}
                </div>
                <dv-octicon
                  icon="arrow-right"
                  class="arrow-right-icon"
                  width="15"
                  height="15"
                ></dv-octicon>
              </a>
            </div>
          </div>
<dv-modal id="heldCommisionReport">
  <div class="modal">
    <div class="modal-body">
      <dv-held-report
        #heldReportComponent
        [modalId]="'heldCommisionReport'"
        [workgroupName]="''"
      >
      </dv-held-report>
    </div>
  </div>
  <div class="modal-background"></div>
</dv-modal>

然后在dv-held-report中,我有以下HTML:

 <h3 class="m-2-vertical">
    Held Commissions Report for {{ name }}
  </h3>

当您单击链接时,将调用openHeldCommissionModal()方法:

openHeldCommissionModal() {
    if (this.viewAsUser) {
      this.heldReportComponent.repId = this.viewAsUser.id
      this.heldReportComponent.name = this.viewAsUser.name
      this.heldReportComponent.isNotViewAsUser = false
      this.heldReportComponent.loggedInUserName = this.loggedUserName
      this.heldReportComponent.detectChanges()
    } else {
      this.heldReportComponent.repId = this.loggedUser.id
      this.heldReportComponent.name = this.loggedUserName
      this.heldReportComponent.isNotViewAsUser = true
      this.heldReportComponent.loggedInUserName = this.loggedUserName
      this.heldReportComponent.detectChanges()
    }
    this.modalService.open('heldCommisionReport')
    event.preventDefault()
    event.stopPropagation()
  }

heldReportComponent中,我有detectChanges()方法:

detectChanges() {
    this.cd.detectChanges()
  }

问题是我需要这样做,因为页面中可以有多个component1,所以每次单击链接时我都需要设置这些值。 name值在组件中进行了更新,但从未反映到UI,将非常感谢您。

0 个答案:

没有答案
相关问题