admin管理员组文章数量:1333702
the curly braces syntax interpolation is used to bind the data from model to view in angularjs.
Generally we display text using it.
Can we populate dropdownlist using the {{}}
syntax in any way?
the curly braces syntax interpolation is used to bind the data from model to view in angularjs.
Generally we display text using it.
Can we populate dropdownlist using the {{}}
syntax in any way?
-
4
Why not use
ng-options
? – AlwaysALearner Commented Sep 12, 2013 at 12:48 - But along with ng-options we have to use ng-model. And I am searching for a technique, which can allow us to populate data without ng-model – Tushar Sharma Commented Sep 12, 2013 at 13:53
4 Answers
Reset to default 5<select>
<option ng-repeat="item in items" value="item.value">{{item.title}}</option>
</select>
You certainly can populate a dropdownlist using the curly braces in angular, but it won't have the expected effect.
If you want to have the data-binding in your select box, you should use the select directive which writes the option
tags in a similar way the ng-repeat
directive would.
Here's an example:
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>
Here's a demo to clear things up: http://jsfiddle/gion_13/TU6tp/
Well, you can populate a dropdownlist this way :
<select ng-model="myItem" ng-options="item.name for item in items"></select>
The selected item will be stored in $scope.myItem
.
Check this page : http://docs.angularjs/api/ng.directive:select
Hope it helps.
You can do something like this:
<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>
本文标签: javascriptPopulate dropdown using curly bracesangularjsStack Overflow
版权声明:本文标题:javascript - Populate dropdown using curly braces + angularjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742272609a2444590.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论