javascript - angular ng-model 绑定的值不更新

查看:128
本文介绍了javascript - angular ng-model 绑定的值不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

angular ng-model 绑定的值不更新

代码主要部分如下

// html代码
<div class="form-group">
  <label>Slot : </label>
  <select class="form-control" ng-model="selectedSlot" ng-options="slot for slot in slotlist"></select>
</div>

//javascript代码
$scope.slotlist = ['Flash Ads', 'Native Ads', 'Lock Ads'];
$scope.selectedSlot = $scope.slotlist[0];

如代码所示,为什么我改变下拉框的值时,$scope.selectedSlot 并没有动态改变?
是不是因为$scope.selectedSlot是数组的一个值,相当于常量?

求详细解答

解决方案

selectedSlot 换成对象格式:
selectedSlot.someAttr

这篇关于javascript - angular ng-model 绑定的值不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆