question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autocomplete - provide reference to the parent component in displayFn

See original GitHub issue

feature 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:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
jymdmancommented, May 2, 2017

You can bind your displayFn to the component with:

[displayWith]="displayFn.bind(this)"

Then you can use this.translateService… without the hack!

0reactions
angular-automatic-lock-bot[bot]commented, Sep 10, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found