Html 角度将全局变量更改反映为函数的局部变量

Html 角度将全局变量更改反映为函数的局部变量,html,angular,typescript,two-way-binding,Html,Angular,Typescript,Two Way Binding,我在使用ngx引导模式时遇到了一个问题。 我有一个html表格,它使用编辑图标打开一个编辑模式,输入中带有表格列的预填充值。像那样 <tr *ngFor="let cat of categories; let i = index"> <th>{{i+1}}</th> <td>{{cat.name}}</td> <td> <

我在使用ngx引导模式时遇到了一个问题。 我有一个html表格,它使用编辑图标打开一个编辑模式,输入中带有表格列的预填充值。像那样

<tr *ngFor="let cat of categories; let i = index">
            <th>{{i+1}}</th>
            <td>{{cat.name}}</td>
            <td>
              <fa-icon
                class="is-icon text-primary mr-2"
                [icon]="faEdit"
                (click)="openModal(updateCategory, cat);">
              </fa-icon>
            </td>
          </tr>

{{i+1}}
{{cat.name}
openModal()将在我的组件中将cat设置为category变量。像这样

openModal(template: TemplateRef<any>, category?: Category) {
    if (category){
      this.category = category;
    }

    this.subscriptions.push(
      this.modalService.onHide.subscribe(() => {
        this.category = {} as Category;
        console.log(this.category);
        this.category = category;
        console.log(this.category, category);
        this.unsubscribe();
      })
    );

    this.modalRef = this.modalService.show(template, this.modalConfig);
  }
openmodel(模板:TemplateRef)

<ng-template #updateCategory>
  <div class="modal-header">
    <h4 class="modal-title pull-left">Update category</h4>
  </div>
  <div class="modal-body">
    <form #updateCategoryForm="ngForm" (ngSubmit)="update(updateCategoryForm); loading = true">
      <div class="form-group">
        <input
          required
          type="text"
          class="form-control"
          placeholder="New name"
          name="updateCategory"
          #updateCategory="ngModel"
          [(ngModel)]="category.name"
          [ngClass]="{'is-invalid': updateCategory.invalid && updateCategory.touched}">
        <div class="invalid-feedback">Category name is required.</div>
      </div>

      <div class="text-center">
        <button
          class="btn btn-primary"
          type="submit"
          [disabled]="!updateCategoryForm.valid">
                  <span
                    class="spinner-border spinner-border-sm"
                    *ngIf="loading"></span>
          Update
        </button>
      </div>
    </form>
  </div>
</ng-template>