Components: Autocomplete: optionSelected not triggered

Created on 18 Oct 2017  路  2Comments  路  Source: angular/components

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.

Most helpful comment

Ok, I clearly misunderstood, it's not emitting a .next, but it just wants a itemSelected($event) callback:

(optionSelected)="itemSelected($event)"

 itemSelected (evt: any) {
    console.log(evt);

All 2 comments

Ok, I clearly misunderstood, it's not emitting a .next, but it just wants a itemSelected($event) callback:

(optionSelected)="itemSelected($event)"

 itemSelected (evt: any) {
    console.log(evt);

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings