简体   繁体   中英

Cannot change md-select value programmatically

Im trying to change the item of md-select programmatically and tried using ng-model-options="{trackBy: '$value.id'}" but this code won't work. Did i missed something so simple?

You can take a look at this DEMO

The md-select element does not have an attribute for ng-model-options since it's not stated in the docs .

Anyways, it looks like you have to instead of track by data , use track by $index .

<md-select ng-model="selectedAnimal">
    <md-option 
        ng-value="item"
        ng-repeat="item in data track by $index">
        {{item.animal}}
    </md-option>
</md-select>

Updated Codepen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM