Can someone please explain to me how does the MatAutocompleteTrigger work?
@ViewChild('autocompleteInput', { read: MatAutocompleteTrigger }) triggerAutocompleteInput: MatAutocompleteTrigger;
<mat-form-field>
<input
#autocompleteInput
matInput
placeholder="Label"
formControlName="label"
[matAutocomplete]="autocompletePanel"
>
</mat-form-field>
<mat-autocomplete #autocompletePanel="matAutocomplete" [displayWith]="displayFn">
<mat-option
*ngFor="let item of items | async"
[value]="item.label"
>
{{ item.label }}
</mat-option>
</mat-autocomplete>
this.triggerAutocompleteInput.optionSelections.subscribe(option => {
console.log('Im gonna kill myself', option );
});
It doesn't do anything. I can be selecting options all day long and nothing will fire. Shouldn't the subscription receive data when I click some option? The this.triggerAutocompleteInput.panelClosingActions works only when you have the autocomplete panel active and you close it with blur.
I don't understand the behavior and I don't understand the documentation.
And what about if you need to access the input through nativeElement? You can't do it when you use it as MatAutocompleteTrigger as far as I can tell.
I'm going crazy.