Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular ngModelChange触发问题_Angular_Typescript - Fatal编程技术网

Angular ngModelChange触发问题

Angular ngModelChange触发问题,angular,typescript,Angular,Typescript,我有一个网站与角。我有一个带有下拉列表的页面,使用(ngModelChange),根据第一个下拉列表中选择的内容,用数据填充另一个下拉列表。如果未选择任何内容,则会用所有数据填充下拉列表 我有一个reste按钮,它删除了这些下拉菜单使用的数组“选定项”的内容(以便重置它们并使它们没有选择任何内容) 我需要一种按以下顺序执行此操作的方法: 重置所选项目 在下拉列表2中插入内容 问题是,代码被执行了,这个东西被正确地放在了下拉列表中,但是DOM似乎在那之后被渲染了,重置所选的项触发了它(ngMo

我有一个网站与角。我有一个带有下拉列表的页面,使用(ngModelChange),根据第一个下拉列表中选择的内容,用数据填充另一个下拉列表。如果未选择任何内容,则会用所有数据填充下拉列表

我有一个reste按钮,它删除了这些下拉菜单使用的数组“选定项”的内容(以便重置它们并使它们没有选择任何内容)

我需要一种按以下顺序执行此操作的方法:

  • 重置所选项目
  • 在下拉列表2中插入内容
问题是,代码被执行了,这个东西被正确地放在了下拉列表中,但是DOM似乎在那之后被渲染了,重置所选的项触发了它(ngModelChange),所以错误的东西被放在了我的下拉列表中

我怎样才能避免呢

下面是一些代码:

HTML

新方法

newMethod(input: any){
 this.resetForm();
 this.selectedTypesFormationItems.push({idTypeFormation: input.idTypeFormation, nomTypeFormation: input.nomTypeFormation });
}

请添加您已经拥有的代码,我相信更多的peeps会很乐意提供帮助。如果您可以添加stackblitz示例,那就太好了。在你的问题中,我们需要更多的信息来完全理解这个问题。我添加了一些代码:)。正如你所看到的,我的问题是我要求重置下拉列表,然后我将数据放入下拉列表,然后(我不想)onNgChange会触发,因为重置和擦除我添加其他数据的内容。
fillTypeFormationDropdown(item: any){

this.dropdownTypesFormationList = [];
this.selectedTypesFormationItems = [];

if (this.selectedCompetencesItems && this.selectedCompetencesItems.length > 0){
  this.serviceFormationRequise.getAllByCompetence("GetByCompetence", this.selectedCompetencesItems[0]['idCpt'])
  .subscribe(response =>  {
      this.sharedSnackBarMessage.changeMessage("TypesFormation sucessfully received");
      this.snackBarService.openSuccessSnackBar(SnackbarMessageComponent);

      this.typeFormationCompetences = response as any;
      //Filling multiselect dropdown
      let dropdown = [];
      this.typeFormationCompetences.forEach(element => {          
        dropdown.push({idTypeFormation: element.idTypeFormation, nomTypeFormation: element.nomTypeFormation });
      }); 
      this.dropdownTypesFormationList = dropdown;
  });
} else {
  if (this.TYPEFORMATION_DATA && this.TYPEFORMATION_DATA.length){
  let dropdown = [];
  this.TYPEFORMATION_DATA.forEach(element => {          
    dropdown.push({idTypeFormation: element.idTypeFormation, nomTypeFormation: element.nomTypeFormation });
  }); 
  this.dropdownTypesFormationList = dropdown;
  }
}
}

resetForm(){
 this.selectedCompetencesItems = [];
 this.selectedTypesFormationItems = [];
}
newMethod(input: any){
 this.resetForm();
 this.selectedTypesFormationItems.push({idTypeFormation: input.idTypeFormation, nomTypeFormation: input.nomTypeFormation });
}