花括号语法插值用于将数据从模型绑定到angularjs中的视图。
通常我们会使用它来显示文字。
我们可以使用{{}}
语法以任何方式填充下拉列表吗?
答案 0 :(得分:5)
<select>
<option ng-repeat="item in items" value="item.value">{{item.title}}</option>
</select>
答案 1 :(得分:1)
您当然可以使用角度的花括号填充下拉列表,但它不会产生预期效果。
如果您希望在选择框中包含数据绑定,则应使用select directive以ng-repeat
指令与http://jsfiddle.net/gion_13/TU6tp/指令类似的方式写入option
标记。
这是一个例子:
<强> JS 强>:
$scope.selectables = [
{ label: 'A', value: 1},
{ label:'B', value: 2},
{ label: 'C', value: 3}
];
// this is the model that's used for the data binding in the select directive
// the default selected item
$scope.selectedItem = $scope.selectables[0];
<强> HTML 强>:
<select
ng-model="selectedItem"
ng-options="o.label for o in selectables">
</select>
<p>Selected item value: {{selectedItem.value}}</p>
这是一个清理过程的演示:{{3}}
答案 2 :(得分:0)
好吧,你可以用这种方式填充下拉列表:
<select ng-model="myItem" ng-options="item.name for item in items"></select>
所选项目将存储在$scope.myItem
。
查看此页面:http://docs.angularjs.org/api/ng.directive:select
希望它有所帮助。
答案 3 :(得分:0)
您可以这样做:
<select ng-model="searchDropdown" ng-class="{active: isDropdownActive}">
<option ng-repeat="item in data.results" value="{{ item[settings.filterOptions[0].value] }}" >{{ item[settings.filterOptions[0].value] }}</option>
</select>