javascript - AngularJS instead of using two ng-show and two dropdowns Can I use one dropdown -
i want use 1 dropdown need satisfy both conditions.
<div ng-show="user == 'admin'"> <div class="col-md-8 col-sm-12 col-xs-12"> <select ng-model="li" > <option ng-repeat="li in list">{{li.name}}</option> </select> </div> </div> <div ng-show="user != 'admin'"> <div class="col-md-8 col-sm-12 col-xs-12"> <select ng-model="li" > <option ng-repeat="li in list|limitto:1">{{li.name}}</option> </select> </div> </div>
you can try this:
<div ng-if="user == 'admin'"> <div class="col-md-8 col-sm-12 col-xs-12"> <select ng-model="li"> <option ng-repeat="li in list">{{li.name}}</option> </select> </div> </div> <div ng-if="user != 'admin'"> <div class="col-md-8 col-sm-12 col-xs-12"> <select ng-model="li"> <option ng-repeat="li in list" ng-if="$first">{{li.name}}</option> </select> </div> </div>
use ng-if
instead of ng-show
, use ng-if="$first"
rather putting limitto:1
filter.
here updated plunker url:http://plnkr.co/edit/cwc9prhqrulcky8umbse?p=preview
Comments
Post a Comment