Autocomplete - provide reference to the parent component in displayFn
See original GitHub issuefeature request:
in displayFn, the this refers to the Mdautocomplete component, not to the custom component in which displayFn is implemented. For translation, I need to grab a translationServive which is injected onto my custom component. My current implementation is kind of a hack:
displayFn(enumValue: any): string {
// this here is acually the Mdautocomplete control
// HACK to get the AutocompleteEnumFormFieldComponent
const that = (<any>this).template._parentView.parent.component;
const translatedValue = that.translateService.instant(enumValue);
return translatedValue;
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top Results From Across the Web
Material.Angular.io mat-autocomplete [displayWith] function ...
I'm running into an issue where I can access locally declared variables in the component controller instantiating the mat- ...
Read more >Customizing Angular mat-autocomplete to handle a million ...
Now, I'm going to build a generic component, where we need to pass the set of records that the mat-autocomplete will show.Here, we...
Read more >Select | Angular Material
To use a native select inside <mat-form-field> , import MatInputModule and add the matNativeControl attribute to the <select> element. Basic select. link code...
Read more >Autocomplete with Angular InstantSearch - Algolia
To implement this, use the Autocomplete component provided by Angular Material. Install and import it. Shell.
Read more >mat multi select with search | The AI Search Engine You Control
This page will provide Angular Material Select with search using <mat-autocomplete> element. The autocomplete is a normal text input with a panel of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can bind your displayFn to the component with:
[displayWith]="displayFn.bind(this)"
Then you can use this.translateService… without the hack!
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.