select标簽的對于大家來說很熟悉了,下面我來講講angularjs中 對select的屬性設定,做出選擇某個下拉選項後控制其他标簽的隐藏;
<select style="height:31px; width:100px" id="rewardMethod"name="rewardMethod" class="status_select" ng-model="state">
<option value="0" ng-selected='rewardMethod == "0"'>自動發放</option>
<option value="1" ng-selected='rewardMethod == "1"'>指定中獎人</option>
<option value="2" ng-selected='rewardMethod == "2"'>不發放獎品</option>
</select>
<div class="form-group" ng-if="state != 2">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1">優惠券</label>
<div class="col-sm-9">
<select style="height:31px; width:100px" id="reward"
name="reward" class="status_select">
<option ng-repeat='item in couponList' ng-value="item.id"
ng-selected="couponInfoid == item.couponName">{{item.couponName}}
總數:{{item.countLimit}}
</option>
</select>
</div>
</div>
<div class="form-group" ng-if="state == 0">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1"><span class="red">*</span>獎品發放數量</label>
<div class="col-sm-9">
<input type="text" name="rewardProvideCount" id="rewardProvideCount"
class="form-control"
check-type="required">
</div>
</div>
</form>
</div>
其中在select中設ng-model = “state”雙向綁定資料,他的值會随你選擇下拉項而改變,就是選中的option的value;在下面的div中設定ng-if="state == 1" 進行控制;
當頁面進行修改操作的時候,需要把原來的值填入表單中,是以加了ng-selected='rewardMethod == "2"'
在controller。js中設定$scope.rewardMethod=2;這樣加載頁面就會選中第三項;效果如下:
如果選擇不發獎: