我正在使用Angular 17,并使用@输入和@输出在父母和子元素之间同步.问题是2之间的同步不一致.(见附件屏幕截图).在某一时刻,同步失败,之后,子进程似乎仍落后父进程1个记录.例如,在屏幕截图中,出现了一个故障,"公寓业主"加载失败.当在下拉列表中进行下一个 Select 时,"公寓业主"将加载到子对象中,而每个新的 Select 都会使子对象比父对象落后一步.

我遗漏了什么?我曾try 通过发出事件来手动更新子对象,但也不起作用.

谢谢!

  async loadAccount(accountID: string) {
this.accountsService.GetAccount(accountID).subscribe((response: Account) => {
  this.page.data.account = response;
  this.onPageUpdate.emit(this.page);   
});    

}

enter image description here

推荐答案

我找到了我问题的原因.我的错误是使用了onChangeSelected,它出现在mat-选项元素上.OnChangeSelected用于使用MULTERSECT且将多次触发的情况.解决方案是使用selectionChange on the mat-select element.我的html现在如下所示:

    <mat-form-field>
  <mat-select #AccountLookup placeholder="**Company **" (selectionChange)="loadAccount($event.value)">
    <mat-option *ngFor="let account of page.accountList| accountLookupFilter: page.selectedAccountStatus"
      [ngClass]="account.statusCode == 2 ? 'alert-error' : 'alert-success'" [value]="account.value">
      {{ account.label }}
    </mat-option>
  </mat-select>
</mat-form-field>

@Naren Murali-感谢您的时间和帮助

Angular相关问答推荐

我使用Ngrx的子集 Select 器不起作用

我如何更新此Ionic应用程序以解决路由问题?

Angular 17不接受带点(.)的路径在开发环境中,它直接抛出一个404错误

HTTP拦截器在Angular 17项目中不起作用

当可观察到的更改时,异步管道不更新视图

从API动态加载MAT表数据时禁用分页

阶段JS画布覆盖 bootstrap 模式

需要做什么才能使 ErrorHandler 正常工作?

无法卸载 angular-cli

Angular 2.0 中 $scope 的替代品

angular4应用程序中输入的最小值和最大值

错误:formControlName 必须与父 formGroup 指令一起使用.您需要添加一个 formGroup 指令

找不到模块'@angular/compiler'

使用 Angular2 将文件上传到 REST API

如何组合两个可观察到的结果?

Angular 2 中的 $implicit 是什么?

Angular 2 filter/search 列表

@HostBinding 与 Angular 中的变量类

如何在 Angular 2 中链接 HTTP 调用?

使用 EventEmitter 传递参数