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

前端 未结 1 468
半阙折子戏
半阙折子戏 2021-02-13 02:13

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:56

    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)
提交回复
热议问题