Skip to content

Autocomplete: optionSelected not triggered #7875

@mxchange

Description

@mxchange

Bug

What is the expected behavior?

Passing in a EventEmitter like:

<mat-autocomplete #auto="matAutocomplete" (optionSelected)="itemSelected">
  <mat-option *ngFor="let option of options" [value]="option.name">
    <span>{{ option.name }}</span>
  </mat-option>
</mat-autocomplete>

And my component:

 itemSelected = new EventEmitter();

 constructor () {
    this.itemSelected.subscribe((item: any) => {
      console.log(item);
    })
  }

To log the item that I clicked

What is the current behavior?

It's not logging anything when I click an option from the list.
It seems it's not triggering a .next on the eventEmitter.

I've also tried to do it with a new Subject, but to no avail.

I must be misunderstanding how this should work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions