components icon indicating copy to clipboard operation
components copied to clipboard

Unable to Bind the value from the service in the autoComplete feature

Open vibingopal opened this issue 9 years ago • 4 comments

#### Bug, feature request
Hi Team,

I am using AutoComplete feature with Material2(Beta 3) + Angular 4 Versions. Now i am unable to bind the value of field  from service in autoComplete.

#### What is the expected behavior?
It should bind two values in the autoComplete box. I can see the values in the drop down of autoComplete but the default value is showing as [object object].

Below is my code
> <md-input-container class="ABC">
                                <input mdInput [mdAutocomplete]="auto">
                           </md-input-container>
                           <md-autocomplete #auto="mdAutocomplete" class="addautoComplete">
                              <md-option *ngFor="let roles of xyz" [value]="roles">
                                    {{roles?.field1}}{{roles?.field2}}
                              </md-option>
 > </md-autocomplete>

Here xyz is the value of Objects return from service.

Any idea on this please?

vibingopal avatar Apr 21 '17 16:04 vibingopal

Not able to bind two values in the autoComplete value field . Any idea please?

                            <input mdInput [mdAutocomplete]="auto">
                       </md-input-container>
                       <md-autocomplete #auto="mdAutocomplete" class="addautoComplete">
                          <md-option *ngFor="let roles of xyz" [value]="roles.field1">
                                {{roles?.field1}}{{roles?.field2}}
                          </md-option>

vibingopal avatar Apr 21 '17 16:04 vibingopal

Have you tried the displayWith option? You add a function in your controller like this:

displayRoles(roles) {
  if (roles != null) return roles.field1;
  else return "";
}

Then add [displayWith]="displayRoles" to your md-autocomplete tag.

jonbrock avatar Apr 21 '17 16:04 jonbrock

I tried the option earlier but i did the typo earlier when accessing the field. But it is resolved now. Thank you Jon

vibingopal avatar Apr 21 '17 19:04 vibingopal

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.