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
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.
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._
Most helpful comment
Ok, I clearly misunderstood, it's not emitting a
.next, but it just wants aitemSelected($event)callback:(optionSelected)="itemSelected($event)"