javascriptangulardropdownmd-autocomplete

md-autocomplete when selecting a dropdown item object it says [Object Object]


        <md-autocomplete
            required
            md-input-class="OfficialClass"
            md-selected-item="selectedOfficial"
            md-search-text="searchText"
            md-items="item in findOfficials(searchText)"
            md-item-text="item.user.display_value"
            md-no-cache="true"
            md-search-text-change="searchTextChange(searchText)"
            md-selected-item-change="selectedItemChange(item.name.value)"
            md-floating-label="New Official"
            md-min-length="3"
            md-autofocus md-autoselect>
          <md-item-template>
            <span md-highlight-text="searchText" md-highlight-flags="^i"> 
             {{item.name.display_value}} - {{item.email.display_value}}</span>
          </md-item-template>
        </md-autocomplete>
      </div> 
      <md-dialog-actions>
        <md-button ng-disable="required" class="md-primary md-raised" aria-label="Submit" ng- 
          click="submitO(selectedOfficial)">Submit Request</md-button>
       \</md-dialog-actions>

I have this autocomplete and right now selectedOfficial returns [Object Object] in my drop down once I select an option. The drop down options as of now display perfectly, the name and email. But once I select the user, I want only the users name to show as the final selected option. Right now I am using selectedOfficial in my method submitO because it has an associated sys_ID with it that i need to reference.

so the selectedOfficial object looks as so:

{
    "sys_id": {
        "display_value": "12345",
        "value": "1234"
    },
    "name": {
        "display_value": "joe bob",
        "value": "joe bob"
    },
    "email": {
        "display_value": "joebob@email.com",
        "value": "joebob@email.com"
    }
}

right now when I hit submitO, it references selectedOfficial and I use the sys_id for a call that I need.

so the question here is, how do I make the dropdown say the display name

I tried md-selected-item="selectedOfficial.name.value" and it still says [Object Object] I even tried item.name.value in the md-select and it still does [object object]

is there some sort of hacky way I can make the dropdown say the objects name value??? I am very stuck and need some help on this its the last piece of the puzzle that I cannot figure out. thanks in advance


Solution

  • md-item-text="item.user.display_value" should be item.name.display_value