AngularJS ng-repeat下使用ng-model
来源:互联网 发布:中国学术期刊网数据库 编辑:程序博客网 时间:2024/05/17 08:30
初学AngularJS 对于作用域的问题不是很了解,因为是自学,没有详细教程,被一个简单的问题困扰了两天。
以下是转载的内容,加深一下个人记忆。
blue:<input type="radio" value="1" ng-model="selectValue"/>red:<input type="radio" value="2" ng-model="selectValue"/>yellow: <input type="radio" value="3" ng-model="selectValue"/>
以上代码实现一个单选框功能,当你选中其中的一个单选框,可以从$scope.selectValue中得到你选中的的选项的value。
同时改变$scope.selectValue的值,也可以让界面上选中相应的单选框。
假设单选框的个数是不固定的,用ng-repeat来展现。
<table><tr ng-repeat="row in collections"><td>{{row.name}}: <input type="radio" value="{{row.value}}" ng-model="selectValue"/></td></tr></table>
当你书写了上述代码后。你会发现点击其中的对话框,$scope.selectValue中并没有保存你选中的对应单选框的值。
这是因为处在ng-repeat之间的代码,对全局的$scope里变量的内容是不可见的,像{{row.name}}里的row,并不是全局$scope里的成员。
而是为ng-repeat创建的子scope里面的。所以要引用全局$scope里的成员,你可以使用$parent 来引用全局的$scope
<table><tr ng-repeat="row in collections"><td>{{row.name}}: <input type="radio" value="{{row.value}}" ng-model="$parent.selectValue"/></td></tr></table>
转载地址:http://zhaoyanblog.com/archives/97.html
0 0
- AngularJS ng-repeat下使用ng-model
- AngularJS ng-repeat下使用ng-model
- AngularJS ng-repeat下使用ng-model
- AngularJS ng-repeat下使用ng-model
- AngularJS ng-repeat下使用ng-model
- AngularJS ng-repeat下使用ng-model
- AngularJS ng-repeat下使用ng-model
- AngularJS ng-repeat下使用ng-model
- AngularJS ng-if ng-repeat下使用ng-model
- AngularJS ng-repeat的使用
- AngularJS中ng-app、ng-model、ng-bind、ng-init、ng-repeat、自定义指令
- AngularJs 在ng-repeat中动态使用ng-model进行双向数据绑定
- AngularJs 在ng-repeat中动态使用ng-model进行双向数据绑定(二)
- angularjs select标签使用ng-repeat标签之后,ng-model无法更新问题解决
- angularjs ng-repeat
- angularjs ng-repeat
- Angularjs中的ng-repeat
- angularJS ng-repeat
- R语言学习之基础知识一
- 开源库混淆Proguard
- java环境变量配置
- redis基本语法和应用场景
- 每天一个Linux命令(1):ls命令
- AngularJS ng-repeat下使用ng-model
- 赋诗一首
- VS Code 调试Node.js express网站(Visual Studio Code)
- ubuntu下安装UltraEdit
- 取消本地文件夹与SVN服务器的关联
- nodeJs处理json
- PowerDesigner 把Comment复制到name中和把name复制到Comment
- “裸辞”期间不掉价,真相在此!
- 先验概率和后验概率