I was trying to use the Material Angular autocomplete and I came across the displayWith function which can be apparently used to be the output that is displayed on selection
You could just change your template to be
Inside of templates this
is a reference to your Component. Then just change your function to
displayFn(id, _this) {
return _this.getValue(id)
}
If [displayWith]
needs to be a function, you could create a property that returns your displayFn
like this:
get createDisplayFn() {
return (id) => {
return this.getValue(id)
}
}
and change your binding to [displayWith]="createDisplayFn"
. As ES6 arrow function can't be rebinded, this
should still be a reference to your component.