angularjs实现下拉列表的选中事件示例
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;这样加载页面就会选中第三项;效果如下:

如果选择不发奖:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
Angular 4 依赖注入学习教程之FactoryProvider的使用(四)
这篇文章主要给大家介绍了关于Angular 4 依赖注入之FactoryProvider使用的相关资料,文中介绍的非常详细,对大家学习或者使用Angular4具有一定的参考学习价值,需要的朋友们下面来一起看看吧。2017-06-06
angular2 ng2-file-upload上传示例代码
这篇文章主要介绍了angular2 ng2-file-upload上传示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-08-08
Angular 4环境准备与Angular cli创建项目详解
Angular4.0来了,更小,更快,改动少,所以下面这篇文章主要给大家介绍了关于Angular 4环境准备与学会使用Angular cli创建项目的相关资料,文中给出了详细的示例代码供大家参考学习,需要的朋友们下面来一起看看吧。2017-05-05
AngularJS ngModel实现指令与输入直接的数据通信
这篇文章主要介绍了AngularJS ngModel实现指令与输入直接的数据通信的相关资料,需要的朋友可以参考下2016-09-09


最新评论