javascript - How to distinct HTML select options with angularjs? -
i have html select tag, code :
<div ng-controller="models"> <select ng-model="mymodel" ng-options="model.name model in models" class="form-control"></select> {{ {selected_model:mymodel.name} }} {{ {selected_model:mymodel.id} }} </div>
and want show mymodel.id==1
.
how can ?
i think question needs bit more of explanation.
do mean want display select each model in models if model.id ==1?
you can filter, while models being written page in select box filter checks if have .id == 1 , if true allows written select.
i imagine means you'll have 1 item in select box duplicate id's in objects bad news bears.
angular.module('yourappname', []) .filter('mymodelfilter', function() { return function(mymodel) { if (mymodel.id == 1) { return mymodel; } }; }) <div ng-controller="models"> <select ng-model="mymodel" ng-options="model.name model in models | mymodelfilter" class="form-control"></select> {{ {selected_model:mymodel.name} }} {{ {selected_model:mymodel.id} }} </div>
edit: p.s.
calling controller , objects in controllers "model" , "models" confusing, i'd recommend choosing different naming convention angularjs mvwhatever framework term "model" has different meaning you're using for.
Comments
Post a Comment