Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.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
如何使用angular5防止在角度材质中打开两次对话框_Angular_Modal Dialog_Angular Material - Fatal编程技术网

如何使用angular5防止在角度材质中打开两次对话框

如何使用angular5防止在角度材质中打开两次对话框,angular,modal-dialog,angular-material,Angular,Modal Dialog,Angular Material,当选择更改事件在每个选项中传递时,会得到多个事件。但是在您选择的一个事件中,您得到了$event.source.selected为true。所以你可以管理它 你的html应该是 I want to display a dialog only once with latest value selected. selectedPersonsInDialog(person){ this.selectedPerson=person; alert(this.selectedPerson); let

当选择更改事件在每个选项中传递时,会得到多个事件。但是在您选择的一个事件中,您得到了
$event.source.selected
true
。所以你可以管理它

你的html应该是

I want to display a dialog only once with latest value selected.

selectedPersonsInDialog(person){
 this.selectedPerson=person;
alert(this.selectedPerson); 
 let dialogRef = this.dialog.open(AddListOfPersonDialog, {
      width: '500px',
      data: { person:this.selectedPerson}
    });
  }*
<mat-autocomplete #auto="matAutocomplete">
                <mat-option *ngFor="let person of filteredPersons | async" [value]="person.name"
                            (onSelectionChange)="selectedPersonsInDialog($event.source.selected,person)">
                    <img style="vertical-align:middle;" aria-hidden  src="{{person.imgUrl}}" width="30" height="30"/>
                    <span>{{ person.name }}</span>
                    <small>ID: {{person.id}}</small>
                </mat-option>
            </mat-autocomplete>
            <mat-autocomplete #auto="matAutocomplete">
            <mat-option *ngFor="let person of filteredPersons |  async" [value]="person.name"
                        (onSelectionChange)="selectedPersonsInDialog($event.source.selected,person)">
                {{person}}
             </mat-option>
        </mat-autocomplete>

你能创建一个工作的plunker或stackblitz吗?HTML:{{person.name}}ID:{{person.ID}请将其添加到代码中
<mat-autocomplete #auto="matAutocomplete">
                <mat-option *ngFor="let person of filteredPersons | async" [value]="person.name"
                            (onSelectionChange)="selectedPersonsInDialog($event.source.selected,person)">
                    <img style="vertical-align:middle;" aria-hidden  src="{{person.imgUrl}}" width="30" height="30"/>
                    <span>{{ person.name }}</span>
                    <small>ID: {{person.id}}</small>
                </mat-option>
            </mat-autocomplete>
            <mat-autocomplete #auto="matAutocomplete">
            <mat-option *ngFor="let person of filteredPersons |  async" [value]="person.name"
                        (onSelectionChange)="selectedPersonsInDialog($event.source.selected,person)">
                {{person}}
             </mat-option>
        </mat-autocomplete>
selectedPersonsInDialog(isSelected: boolean,person){
if(isSelected){
   this.selectedPerson=person;
   alert(this.selectedPerson); 
   let dialogRef = this.dialog.open(AddListOfPersonDialog, {
      width: '500px',
      data: { person:this.selectedPerson}
    });
  }
}