when selection change event pass in every option, so got more then one event. but you got $event.source.selected
is true
in one event which is you selected. so you can manage it.
your html should be like
<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>
your component function should be like
selectedPersonsInDialog(isSelected: boolean,person){
if(isSelected){
this.selectedPerson=person;
alert(this.selectedPerson);
let dialogRef = this.dialog.open(AddListOfPersonDialog, {
width: '500px',
data: { person:this.selectedPerson}
});
}
}