Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of md-autocomplete items?

I have grid-ui where cell is angular material md-autocomplete.

I wrote demo: codepen where I run (for simulate only) ng-repeat and try to select different value per row.

However whenever I do when I change one item, all other rows change as well. What am I doing wrong?

My HTML:

 <tr  layout="row" ng-repeat="item in ctrl.items" flex>
        <td class="sc_color" flex>{{$index+1}}.color</td>
        <td flex>
            <md-autocomplete style="margin-bottom:10px;"
        md-selected-item="item.selectedItem"
        md-search-text="ctrl.searchText"
        md-items="item in ctrl.querySearch(ctrl.searchText)"
        md-item-text="item.display"
        md-min-length="0"
        placeholder="Pick a color">
    <md-item-template>
        <span md-highlight-text="ctrl.searchText" md-highlight-flags="^i">{{item.display}}</span>
    </md-item-template>
</md-autocomplete>
        </td>
    </tr>

My items:

self.items = [
      {
        selectedItem: 'aa'
      },
       {
        selectedItem: 'bbb'
      }
    ];  

I use md-selected-item but sounds like its the same for all items.

like image 672
snaggs Avatar asked Feb 08 '23 15:02

snaggs


2 Answers

It's just because all the field are linked to the same variable : ctrl.searchtext.

Just have to change this :

md-search-text="ctrl.searchText"
md-items="item in ctrl.querySearch(ctrl.searchText)"

By this :

md-search-text="ctrl['searchText' + $index]"
md-items="item in ctrl.querySearch(ctrl['searchText' + $index])"

Codepen : http://codepen.io/anon/pen/dMPLMb

like image 146
BENARD Patrick Avatar answered Feb 13 '23 07:02

BENARD Patrick


Instead of using you can use scope variable like this

md-search-text="searchQuery"
md-items="item in ctrl.querySearch(searchQuery)"

In this case it use md-autocomplete scope and you don't need to worry about query variable anymore.

The @pbenard solution is ok for the list which does not have pagination or you don't insert new item at first index

like image 22
navid_gh Avatar answered Feb 13 '23 07:02

navid_gh