Angular material auto-complete displayWith @Input

Angular Material 2 have awesome components that are really easy to use. Except one the auto-complete. This one is a little brain teaser. Although the documentation provides examples, it is not always really straight-forward how to use designed API. For example the displayWith @Input.

Screen Shot 2017-07-12 at 20.27.44

Let’s say you want to display state code instead of full name as is in above picture.

If you want to parse displayed value from some kind of list or ask your service you have to bind the “right” this. And you have two options, you can either use arrow function, or the bind() function. In this example I will use bind();

So now you have access to the component this from the parseHash() function.

Here is the plunker with example taken from material2 documentation.

Related Post

MacBook wifi issue – OS X keeps reconnecting Last few weeks I was facing annoying wifi problems. My mac was reconnecting every 5 minutes. On top of that BSSID was reseting so I saw BSSID changing...
Free Better Battery Stats and Time Remaining for M... Better Battery Stats and Time Remaining for Mac OS TL;DR; Do you miss the time remaining indicator on your MacBook, MacBook Air, or MacBook Pro? He...
PPTP VPN on MAC OS X Sierra, High Sierra and Mojav... PPTP VPN for Mac OS X Introduction PPTP VPN is no longer supported on macOS Sierra and High Sierra and that is just fine, because there are some se...
Right Click to Create New File on Mac OS X TL;DR; Windows has a lot of cons but it has also some pros. One of them is a smooth way to create empty file on right-click. Mac OS doesn't come with...
Convert HEIC to JPG on Right Click for Free Convert HEIC to JPG on Right-Click In iOS 11 Apple is replacing the JPEG image format with the new HEIC alternative. But what to do when device or p...
FAQ: Mac OS X Services HEIC to JPG on Right-Click Service Q: Where’d all my services go? I don’t see anything in the Services menu. A: If you don’t select anything before...
Buy me a coffeeOut of coffee 😱, please help!