I am trying to come up with something like the tagging feature on Facebook i.e whenever '@' key is pressed my autocomplete should be triggered and I should be able to see the option corresponding to the data typed post '@'.
I am unable to bind the autocomplete on keydown(or any key event)
Any suggestion on how to achieve this functionality would be appreciated, My last resort is coming up with my own autocomplete module
You can do the following to accomplish this.
Create a
ViewChild
to get reference to theMatAutocompleteTrigger
Create a
HostListener
to set theformControl
value to@
and open the panel when the@
key is pressed.Stackblitz
In this stackblitz, click the view to set focus or the event will not trigger the
HostListener
https://stackblitz.com/edit/angular-4x3zte?embed=1&file=app/autocomplete-overview-example.ts