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>