javascript - Populate dropdown using curly braces + angularjs - Stack Overflow

the curly braces syntax interpolation is used to bind the data from model to view in angularjs.Generall

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?

Share Improve this question edited Sep 12, 2013 at 12:48 Richard Ev 54.2k61 gold badges194 silver badges281 bronze badges asked Sep 12, 2013 at 12:47 Tushar SharmaTushar Sharma 3471 gold badge3 silver badges11 bronze badges 2
  • 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
Add a ment  | 

4 Answers 4

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742272609a4412984.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信