How to make angularJS ng-model work with objects in select elements?

前端 未结 1 1778
南旧
南旧 2021-02-13 01:51

I have a problem with ng-model on a select element when passing an object from option elements. So, imagine we have an array of columns from a table ca

相关标签:
1条回答
  • 2021-02-13 02:32

    You can use ng-options to bind the selected object to a model:

    <div class="form-field" ng-repeat="filter in filters">
       <select ng-options="column.name for column in columns" ng-model="filter.value">
             <option value="" disabled>Choose filter</option>
       </select>
    
       <input type="text" ng-model="filter.value.name">
    </div>
    

    Plunker

    Updated answer:

    <div class="form-field" ng-repeat="filter in filters">
       <select ng-options="column.name for column in columns" ng-model="filters[$index]">
         <option value="" disabled>Choose filter</option>
       </select>
    
       <input type="text" ng-model="filters[$index].name">
    </div>
    
    0 讨论(0)
提交回复
热议问题