Why does angular select onModelChange execute so many times?

    <nz-form-item>
      <nz-form-label nzRequired nzSpan="7"></nz-form-label>
      <nz-form-control nzSpan="10">
        <nz-select formControlName="roomId" nzAllowClear nzShowSearch (nzOnSearch)="onSearchRoom($event)" (ngModelChange)="onSearchCustomer()">
          <nz-option *ngFor="let item of roomList" [nzValue]="item.room_id" [nzLabel]="item.room_no"></nz-option>
        </nz-select>
        <nz-form-explain *ngIf="isInvalid("roomId")"></nz-form-explain>
      </nz-form-control>
    </nz-form-item>
    
      async onSearchRoom(search?) {
    const { data } = await this.api.get("repair/rooms")({
      room_no: search,
    });
    this.roomList = data;
     console.log("change room")
  }

  async onSearchCustomer() {
    const { data } = await this.api.get("repair/get-customer-by-room")({
      room_id: this.add.value.roomId,
    });
    this.customer_id = data.customer_id
    console.log(data.customer_name)
    this.add.setValue({
      customerName: data.customer_name,
      roomId: this.add.value.roomId,
      repairPerson: this.add.value.repairPerson,
      repairPhone: this.add.value.repairPhone,
      repairTime: this.add.value.repairTime,
      repairOrderTime: this.add.value.repairOrderTime,
      // projectId: this.add.value.projectId,
      projectName: this.add.value.projectName,
      repairCostType: this.add.value.repairCostType,
      repairCostPrice: this.add.value.repairCostPrice,
    })
  }

clipboard.png

the choice you want to achieve is to apply for option changes in the repair room and request the associated household to assign a value to the household who applied for repair, but will always call onSearchCustomer.

Nov.29,2021
Menu