Angular mat-autocomplete : How to display the option name and not the value in the inputAngular CLI SASS optionsHow to detect when an @Input() value changes in Angular?Angular Material AutoComplete Not Loading Options MVCAngular Material - Custom Autocomplete componentAngular material - autocomplete mat-errorMat-Select Display Object Property i.e. customer.name from Previously Selected/Saved ValueAutomatic fill a mat-select option from server with another valueHow to disable a mat Input field based on the value of a mat radio button?Angular Material conflicting with ReactiveForms<input> element inside <option> tag angular material

Should I have shared a document with a former employee?

How to tell readers that I know my story is factually incorrect?

What's the physical meaning of the statement that "photons don't have positions"?

Why would word of Princess Leia's capture generate sympathy for the Rebellion in the Senate?

What is a Kravchuk transform and how is it related to Fourier transforms?

Why teach C using scanf without talking about command line arguments?

Does unblocking power bar outlets through short extension cords increase fire risk?

When will the last unambiguous evidence of mankind disappear?

Formating slide

Why does a tetrahedral molecule like methane have a dipole moment of zero?

Locked-up DOS computer beeped on keypress. What mechanism caused that?

You have no, but can try for yes

Should I have one hand on the throttle during engine ignition?

What makes MOVEQ quicker than a normal MOVE in 68000 assembly?

When we are talking about black hole evaporation - what exactly happens?

Inside Out and Back to Front

Are there foods that astronauts are explicitly never allowed to eat?

Does the Bracer of Flying Daggers really let a thief make 4 attacks per round?

Improving an O(N^2) function (all entities iterating over all other entities)

Why is this guy handcuffed censored?

How should I interpret a promising preprint that was never published in a peer-reviewed journal?

Consequences of stalling while sideslipping in a glider?

When a ball on a rope swings in a circle, is there both centripetal force and tension force?

How to get a type of "screech" on guitar



Angular mat-autocomplete : How to display the option name and not the value in the input


Angular CLI SASS optionsHow to detect when an @Input() value changes in Angular?Angular Material AutoComplete Not Loading Options MVCAngular Material - Custom Autocomplete componentAngular material - autocomplete mat-errorMat-Select Display Object Property i.e. customer.name from Previously Selected/Saved ValueAutomatic fill a mat-select option from server with another valueHow to disable a mat Input field based on the value of a mat radio button?Angular Material conflicting with ReactiveForms<input> element inside <option> tag angular material






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm using the mat-autocomplete widget under my Angular app :



 <mat-form-field class="col-md-3" color="warn">
<input type="text"
id="libelleShop"
#inputSelectShop
placeholder="Selectionner la boutique"
matInput
formControlName="libelleShop"
ngDefaultControl
[matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete""
(optionSelected)="onShopSelectionChanged($event)">
<mat-option *ngFor="let shop of shopData" [value]="shop.value">
shop.name
</mat-option>
</mat-autocomplete>
</mat-form-field>


my Shop data is like this :



shopData = [
name: 'AAA' , value :'11',
name: 'BBB', value :'22',
name: 'CCC', value : '33'
];


Like this - options are displayed by name , but when selection the input displaysit by the value not the name.



Knowing that i need the value for other treatment and i won't change the [value] in the mat-automplete.



How may i take reference for the name to the input ??



Suggestions ??










share|improve this question






























    0















    I'm using the mat-autocomplete widget under my Angular app :



     <mat-form-field class="col-md-3" color="warn">
    <input type="text"
    id="libelleShop"
    #inputSelectShop
    placeholder="Selectionner la boutique"
    matInput
    formControlName="libelleShop"
    ngDefaultControl
    [matAutocomplete]="auto">
    <mat-autocomplete #auto="matAutocomplete""
    (optionSelected)="onShopSelectionChanged($event)">
    <mat-option *ngFor="let shop of shopData" [value]="shop.value">
    shop.name
    </mat-option>
    </mat-autocomplete>
    </mat-form-field>


    my Shop data is like this :



    shopData = [
    name: 'AAA' , value :'11',
    name: 'BBB', value :'22',
    name: 'CCC', value : '33'
    ];


    Like this - options are displayed by name , but when selection the input displaysit by the value not the name.



    Knowing that i need the value for other treatment and i won't change the [value] in the mat-automplete.



    How may i take reference for the name to the input ??



    Suggestions ??










    share|improve this question


























      0












      0








      0








      I'm using the mat-autocomplete widget under my Angular app :



       <mat-form-field class="col-md-3" color="warn">
      <input type="text"
      id="libelleShop"
      #inputSelectShop
      placeholder="Selectionner la boutique"
      matInput
      formControlName="libelleShop"
      ngDefaultControl
      [matAutocomplete]="auto">
      <mat-autocomplete #auto="matAutocomplete""
      (optionSelected)="onShopSelectionChanged($event)">
      <mat-option *ngFor="let shop of shopData" [value]="shop.value">
      shop.name
      </mat-option>
      </mat-autocomplete>
      </mat-form-field>


      my Shop data is like this :



      shopData = [
      name: 'AAA' , value :'11',
      name: 'BBB', value :'22',
      name: 'CCC', value : '33'
      ];


      Like this - options are displayed by name , but when selection the input displaysit by the value not the name.



      Knowing that i need the value for other treatment and i won't change the [value] in the mat-automplete.



      How may i take reference for the name to the input ??



      Suggestions ??










      share|improve this question
















      I'm using the mat-autocomplete widget under my Angular app :



       <mat-form-field class="col-md-3" color="warn">
      <input type="text"
      id="libelleShop"
      #inputSelectShop
      placeholder="Selectionner la boutique"
      matInput
      formControlName="libelleShop"
      ngDefaultControl
      [matAutocomplete]="auto">
      <mat-autocomplete #auto="matAutocomplete""
      (optionSelected)="onShopSelectionChanged($event)">
      <mat-option *ngFor="let shop of shopData" [value]="shop.value">
      shop.name
      </mat-option>
      </mat-autocomplete>
      </mat-form-field>


      my Shop data is like this :



      shopData = [
      name: 'AAA' , value :'11',
      name: 'BBB', value :'22',
      name: 'CCC', value : '33'
      ];


      Like this - options are displayed by name , but when selection the input displaysit by the value not the name.



      Knowing that i need the value for other treatment and i won't change the [value] in the mat-automplete.



      How may i take reference for the name to the input ??



      Suggestions ??







      angular angular-material angular-material2 angular-material-6






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 11:41









      Abhishek Kumar

      1,6034 silver badges18 bronze badges




      1,6034 silver badges18 bronze badges










      asked Mar 26 at 10:57









      firasKoubaafirasKoubaa

      1,4996 gold badges23 silver badges54 bronze badges




      1,4996 gold badges23 silver badges54 bronze badges






















          4 Answers
          4






          active

          oldest

          votes


















          3














          You can use the displayWith attribute of Mat autocomplete and pass in a function that will return the desired formatted string.



          In your example:






          displayFn(shop: Shop): string 
          return shop.name;

          <mat-autocomplete #auto="matAutocomplete"" (optionSelected)="onShopSelectionChanged($event)" [displayWith]="displayFn">
          <mat-option *ngFor="let shop of shopData" [value]="shop.value">
          shop.name
          </mat-option>
          </mat-autocomplete>








          share|improve this answer

























          • This won't work because of [value]="shop.value" which the OP doesn't want to change. Also, displayWith is a feature on mat-autocomplete, not mat-option.

            – G. Tranter
            Mar 26 at 20:13












          • Indeed my mistake, said it in the answer but not in the code... Anyway the lookup is the right solution in that case :)

            – Alex
            Mar 26 at 23:20


















          1














          Because you don't want to change [value]="shop.value", your only resort is to lookup the name based on value in a function used with the displayWith feature:



          <mat-autocomplete ... [displayWith]="getShopName" ... >


          getShopName(value)
          const results = this.shopData.filter(shop => shop.value === value);
          if (results.length)
          return results[0].name;

          return value;






          share|improve this answer






























            0














            In your model 'shopData' add the ':' character after 'value' or:



            export interface Shop 
            name: string;
            value: number;


            shopData: Shop[] = [
            name: 'AAA' , value: 11,
            name: 'BBB', value: 22,
            name: 'CCC', value: 33
            ];





            share|improve this answer























            • that was not the problem , my purpose is how to display the name and not the value

              – firasKoubaa
              Mar 26 at 11:24


















            0














            You can use FormControl on input tag and can change the value of this form-control using patchValue method.



            Use (onSelectionChange)="onEnter($event)" and find the selectedArray option using the selected value, and from that selected option object update the value of input with any of the options key.


            Html :



            <form class="example-form">
            <mat-form-field class="example-full-width">
            <input #stateInput (keyup)="0" matInput placeholder="State"
            aria-label="State" [matAutocomplete]="auto" [formControl]="stateCtrl">
            <mat-autocomplete #auto="matAutocomplete">
            <mat-option (onSelectionChange)="stateInput.value !=undefined &&
            onEnter($event)" *ngFor="let state of filteredStates | async"
            [value]="state.name">
            <img style="vertical-align:middle;" aria-hidden
            src="state.flag" height="25" />
            <span> state.name </span> |
            <small>Population: state.population</small>
            </mat-option>
            </mat-autocomplete>
            </mat-form-field>



            Ts file :



             onEnter(evt: any)
            const selectedState = this.states.find(state =>
            state.name.toLowerCase()==evt.source.value.toLowerCase());
            if (evt.source.selected)
            console.log(selectedState);
            if(selectedState)
            setTimeout(()=>
            this.stateCtrl.patchValue(selectedState.population);
            , 0);





            Stackblitz Demo with other data






            share|improve this answer



























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55355450%2fangular-mat-autocomplete-how-to-display-the-option-name-and-not-the-value-in-t%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              You can use the displayWith attribute of Mat autocomplete and pass in a function that will return the desired formatted string.



              In your example:






              displayFn(shop: Shop): string 
              return shop.name;

              <mat-autocomplete #auto="matAutocomplete"" (optionSelected)="onShopSelectionChanged($event)" [displayWith]="displayFn">
              <mat-option *ngFor="let shop of shopData" [value]="shop.value">
              shop.name
              </mat-option>
              </mat-autocomplete>








              share|improve this answer

























              • This won't work because of [value]="shop.value" which the OP doesn't want to change. Also, displayWith is a feature on mat-autocomplete, not mat-option.

                – G. Tranter
                Mar 26 at 20:13












              • Indeed my mistake, said it in the answer but not in the code... Anyway the lookup is the right solution in that case :)

                – Alex
                Mar 26 at 23:20















              3














              You can use the displayWith attribute of Mat autocomplete and pass in a function that will return the desired formatted string.



              In your example:






              displayFn(shop: Shop): string 
              return shop.name;

              <mat-autocomplete #auto="matAutocomplete"" (optionSelected)="onShopSelectionChanged($event)" [displayWith]="displayFn">
              <mat-option *ngFor="let shop of shopData" [value]="shop.value">
              shop.name
              </mat-option>
              </mat-autocomplete>








              share|improve this answer

























              • This won't work because of [value]="shop.value" which the OP doesn't want to change. Also, displayWith is a feature on mat-autocomplete, not mat-option.

                – G. Tranter
                Mar 26 at 20:13












              • Indeed my mistake, said it in the answer but not in the code... Anyway the lookup is the right solution in that case :)

                – Alex
                Mar 26 at 23:20













              3












              3








              3







              You can use the displayWith attribute of Mat autocomplete and pass in a function that will return the desired formatted string.



              In your example:






              displayFn(shop: Shop): string 
              return shop.name;

              <mat-autocomplete #auto="matAutocomplete"" (optionSelected)="onShopSelectionChanged($event)" [displayWith]="displayFn">
              <mat-option *ngFor="let shop of shopData" [value]="shop.value">
              shop.name
              </mat-option>
              </mat-autocomplete>








              share|improve this answer















              You can use the displayWith attribute of Mat autocomplete and pass in a function that will return the desired formatted string.



              In your example:






              displayFn(shop: Shop): string 
              return shop.name;

              <mat-autocomplete #auto="matAutocomplete"" (optionSelected)="onShopSelectionChanged($event)" [displayWith]="displayFn">
              <mat-option *ngFor="let shop of shopData" [value]="shop.value">
              shop.name
              </mat-option>
              </mat-autocomplete>








              displayFn(shop: Shop): string 
              return shop.name;

              <mat-autocomplete #auto="matAutocomplete"" (optionSelected)="onShopSelectionChanged($event)" [displayWith]="displayFn">
              <mat-option *ngFor="let shop of shopData" [value]="shop.value">
              shop.name
              </mat-option>
              </mat-autocomplete>





              displayFn(shop: Shop): string 
              return shop.name;

              <mat-autocomplete #auto="matAutocomplete"" (optionSelected)="onShopSelectionChanged($event)" [displayWith]="displayFn">
              <mat-option *ngFor="let shop of shopData" [value]="shop.value">
              shop.name
              </mat-option>
              </mat-autocomplete>






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 26 at 23:17

























              answered Mar 26 at 11:27









              AlexAlex

              2262 silver badges12 bronze badges




              2262 silver badges12 bronze badges












              • This won't work because of [value]="shop.value" which the OP doesn't want to change. Also, displayWith is a feature on mat-autocomplete, not mat-option.

                – G. Tranter
                Mar 26 at 20:13












              • Indeed my mistake, said it in the answer but not in the code... Anyway the lookup is the right solution in that case :)

                – Alex
                Mar 26 at 23:20

















              • This won't work because of [value]="shop.value" which the OP doesn't want to change. Also, displayWith is a feature on mat-autocomplete, not mat-option.

                – G. Tranter
                Mar 26 at 20:13












              • Indeed my mistake, said it in the answer but not in the code... Anyway the lookup is the right solution in that case :)

                – Alex
                Mar 26 at 23:20
















              This won't work because of [value]="shop.value" which the OP doesn't want to change. Also, displayWith is a feature on mat-autocomplete, not mat-option.

              – G. Tranter
              Mar 26 at 20:13






              This won't work because of [value]="shop.value" which the OP doesn't want to change. Also, displayWith is a feature on mat-autocomplete, not mat-option.

              – G. Tranter
              Mar 26 at 20:13














              Indeed my mistake, said it in the answer but not in the code... Anyway the lookup is the right solution in that case :)

              – Alex
              Mar 26 at 23:20





              Indeed my mistake, said it in the answer but not in the code... Anyway the lookup is the right solution in that case :)

              – Alex
              Mar 26 at 23:20













              1














              Because you don't want to change [value]="shop.value", your only resort is to lookup the name based on value in a function used with the displayWith feature:



              <mat-autocomplete ... [displayWith]="getShopName" ... >


              getShopName(value)
              const results = this.shopData.filter(shop => shop.value === value);
              if (results.length)
              return results[0].name;

              return value;






              share|improve this answer



























                1














                Because you don't want to change [value]="shop.value", your only resort is to lookup the name based on value in a function used with the displayWith feature:



                <mat-autocomplete ... [displayWith]="getShopName" ... >


                getShopName(value)
                const results = this.shopData.filter(shop => shop.value === value);
                if (results.length)
                return results[0].name;

                return value;






                share|improve this answer

























                  1












                  1








                  1







                  Because you don't want to change [value]="shop.value", your only resort is to lookup the name based on value in a function used with the displayWith feature:



                  <mat-autocomplete ... [displayWith]="getShopName" ... >


                  getShopName(value)
                  const results = this.shopData.filter(shop => shop.value === value);
                  if (results.length)
                  return results[0].name;

                  return value;






                  share|improve this answer













                  Because you don't want to change [value]="shop.value", your only resort is to lookup the name based on value in a function used with the displayWith feature:



                  <mat-autocomplete ... [displayWith]="getShopName" ... >


                  getShopName(value)
                  const results = this.shopData.filter(shop => shop.value === value);
                  if (results.length)
                  return results[0].name;

                  return value;







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 26 at 20:21









                  G. TranterG. Tranter

                  6,7491 gold badge9 silver badges31 bronze badges




                  6,7491 gold badge9 silver badges31 bronze badges





















                      0














                      In your model 'shopData' add the ':' character after 'value' or:



                      export interface Shop 
                      name: string;
                      value: number;


                      shopData: Shop[] = [
                      name: 'AAA' , value: 11,
                      name: 'BBB', value: 22,
                      name: 'CCC', value: 33
                      ];





                      share|improve this answer























                      • that was not the problem , my purpose is how to display the name and not the value

                        – firasKoubaa
                        Mar 26 at 11:24















                      0














                      In your model 'shopData' add the ':' character after 'value' or:



                      export interface Shop 
                      name: string;
                      value: number;


                      shopData: Shop[] = [
                      name: 'AAA' , value: 11,
                      name: 'BBB', value: 22,
                      name: 'CCC', value: 33
                      ];





                      share|improve this answer























                      • that was not the problem , my purpose is how to display the name and not the value

                        – firasKoubaa
                        Mar 26 at 11:24













                      0












                      0








                      0







                      In your model 'shopData' add the ':' character after 'value' or:



                      export interface Shop 
                      name: string;
                      value: number;


                      shopData: Shop[] = [
                      name: 'AAA' , value: 11,
                      name: 'BBB', value: 22,
                      name: 'CCC', value: 33
                      ];





                      share|improve this answer













                      In your model 'shopData' add the ':' character after 'value' or:



                      export interface Shop 
                      name: string;
                      value: number;


                      shopData: Shop[] = [
                      name: 'AAA' , value: 11,
                      name: 'BBB', value: 22,
                      name: 'CCC', value: 33
                      ];






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 26 at 11:16









                      Pablo M.Pablo M.

                      415 bronze badges




                      415 bronze badges












                      • that was not the problem , my purpose is how to display the name and not the value

                        – firasKoubaa
                        Mar 26 at 11:24

















                      • that was not the problem , my purpose is how to display the name and not the value

                        – firasKoubaa
                        Mar 26 at 11:24
















                      that was not the problem , my purpose is how to display the name and not the value

                      – firasKoubaa
                      Mar 26 at 11:24





                      that was not the problem , my purpose is how to display the name and not the value

                      – firasKoubaa
                      Mar 26 at 11:24











                      0














                      You can use FormControl on input tag and can change the value of this form-control using patchValue method.



                      Use (onSelectionChange)="onEnter($event)" and find the selectedArray option using the selected value, and from that selected option object update the value of input with any of the options key.


                      Html :



                      <form class="example-form">
                      <mat-form-field class="example-full-width">
                      <input #stateInput (keyup)="0" matInput placeholder="State"
                      aria-label="State" [matAutocomplete]="auto" [formControl]="stateCtrl">
                      <mat-autocomplete #auto="matAutocomplete">
                      <mat-option (onSelectionChange)="stateInput.value !=undefined &&
                      onEnter($event)" *ngFor="let state of filteredStates | async"
                      [value]="state.name">
                      <img style="vertical-align:middle;" aria-hidden
                      src="state.flag" height="25" />
                      <span> state.name </span> |
                      <small>Population: state.population</small>
                      </mat-option>
                      </mat-autocomplete>
                      </mat-form-field>



                      Ts file :



                       onEnter(evt: any)
                      const selectedState = this.states.find(state =>
                      state.name.toLowerCase()==evt.source.value.toLowerCase());
                      if (evt.source.selected)
                      console.log(selectedState);
                      if(selectedState)
                      setTimeout(()=>
                      this.stateCtrl.patchValue(selectedState.population);
                      , 0);





                      Stackblitz Demo with other data






                      share|improve this answer





























                        0














                        You can use FormControl on input tag and can change the value of this form-control using patchValue method.



                        Use (onSelectionChange)="onEnter($event)" and find the selectedArray option using the selected value, and from that selected option object update the value of input with any of the options key.


                        Html :



                        <form class="example-form">
                        <mat-form-field class="example-full-width">
                        <input #stateInput (keyup)="0" matInput placeholder="State"
                        aria-label="State" [matAutocomplete]="auto" [formControl]="stateCtrl">
                        <mat-autocomplete #auto="matAutocomplete">
                        <mat-option (onSelectionChange)="stateInput.value !=undefined &&
                        onEnter($event)" *ngFor="let state of filteredStates | async"
                        [value]="state.name">
                        <img style="vertical-align:middle;" aria-hidden
                        src="state.flag" height="25" />
                        <span> state.name </span> |
                        <small>Population: state.population</small>
                        </mat-option>
                        </mat-autocomplete>
                        </mat-form-field>



                        Ts file :



                         onEnter(evt: any)
                        const selectedState = this.states.find(state =>
                        state.name.toLowerCase()==evt.source.value.toLowerCase());
                        if (evt.source.selected)
                        console.log(selectedState);
                        if(selectedState)
                        setTimeout(()=>
                        this.stateCtrl.patchValue(selectedState.population);
                        , 0);





                        Stackblitz Demo with other data






                        share|improve this answer



























                          0












                          0








                          0







                          You can use FormControl on input tag and can change the value of this form-control using patchValue method.



                          Use (onSelectionChange)="onEnter($event)" and find the selectedArray option using the selected value, and from that selected option object update the value of input with any of the options key.


                          Html :



                          <form class="example-form">
                          <mat-form-field class="example-full-width">
                          <input #stateInput (keyup)="0" matInput placeholder="State"
                          aria-label="State" [matAutocomplete]="auto" [formControl]="stateCtrl">
                          <mat-autocomplete #auto="matAutocomplete">
                          <mat-option (onSelectionChange)="stateInput.value !=undefined &&
                          onEnter($event)" *ngFor="let state of filteredStates | async"
                          [value]="state.name">
                          <img style="vertical-align:middle;" aria-hidden
                          src="state.flag" height="25" />
                          <span> state.name </span> |
                          <small>Population: state.population</small>
                          </mat-option>
                          </mat-autocomplete>
                          </mat-form-field>



                          Ts file :



                           onEnter(evt: any)
                          const selectedState = this.states.find(state =>
                          state.name.toLowerCase()==evt.source.value.toLowerCase());
                          if (evt.source.selected)
                          console.log(selectedState);
                          if(selectedState)
                          setTimeout(()=>
                          this.stateCtrl.patchValue(selectedState.population);
                          , 0);





                          Stackblitz Demo with other data






                          share|improve this answer















                          You can use FormControl on input tag and can change the value of this form-control using patchValue method.



                          Use (onSelectionChange)="onEnter($event)" and find the selectedArray option using the selected value, and from that selected option object update the value of input with any of the options key.


                          Html :



                          <form class="example-form">
                          <mat-form-field class="example-full-width">
                          <input #stateInput (keyup)="0" matInput placeholder="State"
                          aria-label="State" [matAutocomplete]="auto" [formControl]="stateCtrl">
                          <mat-autocomplete #auto="matAutocomplete">
                          <mat-option (onSelectionChange)="stateInput.value !=undefined &&
                          onEnter($event)" *ngFor="let state of filteredStates | async"
                          [value]="state.name">
                          <img style="vertical-align:middle;" aria-hidden
                          src="state.flag" height="25" />
                          <span> state.name </span> |
                          <small>Population: state.population</small>
                          </mat-option>
                          </mat-autocomplete>
                          </mat-form-field>



                          Ts file :



                           onEnter(evt: any)
                          const selectedState = this.states.find(state =>
                          state.name.toLowerCase()==evt.source.value.toLowerCase());
                          if (evt.source.selected)
                          console.log(selectedState);
                          if(selectedState)
                          setTimeout(()=>
                          this.stateCtrl.patchValue(selectedState.population);
                          , 0);





                          Stackblitz Demo with other data







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 26 at 11:42

























                          answered Mar 26 at 11:34









                          Abhishek KumarAbhishek Kumar

                          1,6034 silver badges18 bronze badges




                          1,6034 silver badges18 bronze badges



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55355450%2fangular-mat-autocomplete-how-to-display-the-option-name-and-not-the-value-in-t%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                              Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript