Angularjs 将所选选项值绑定到ng repeat内的模型
当我以这种方式将选项值绑定到模型时,它是有效的。Angularjs 将所选选项值绑定到ng repeat内的模型,angularjs,Angularjs,当我以这种方式将选项值绑定到模型时,它是有效的。 {{profile\u filter}}将包含{{option.label}}: <select ng-model="profile_filter"> <option ng-repeat="option in showCase.filters" value="{{option.label}}"> {{option.label}} </option> </select> /
{{profile\u filter}}
将包含{{option.label}}
:
<select ng-model="profile_filter">
<option ng-repeat="option in showCase.filters" value="{{option.label}}">
{{option.label}}
</option>
</select>
// Show Selected Option :
<div>{{profile_filter}}</div>
问题:我应该采取什么方法来解决这个问题?
提前感谢。我不确定您想要的是什么,因为您有多个选择器,但是如果您想要,可以将profile\u filter设置为一个数组,并将每个select绑定到该数组中自己的值
<div class="filters" ng-repeat="filter in showCase.filters">
<label>{{filter.label}}
<select ng-model="profile_filter">
<option ng-repeat="option in filter.options" value="{{option.label}}">
{{option.label}}
</option>
</select>
</label>
</div>
// Empty
<div>{{profile_filter}}</div>
<div ng-controller="MyCtrl">
<div class="filters" ng-repeat="filter in showCase.filters">
<label>{{filter.label}}
<!-- bind to a specific index in the controller array using $index -->
<select ng-model="profile_filter[$index]">
<option ng-repeat="option in filter.options" value="{{option.label}}">{{option.label}}</option>
</select>
</label>
</div>
<!-- display the first value -->
<div>{{profile_filter[0]}}</div>
</div>
$scope.profile_filter = [];
$scope.showCase = {
filters: [
{
label: 'hello',
options: [ { label: 'A' }, { label: 'B' }]
},
{
label: 'hello again',
options: [ { label: 'C' }, { label: 'D' }]
}]
};