发表于: 2016-11-12 00:23:58
0 1786
完成的事;修改任务8
明天计划的事:做任务8表单验证
遇到的问题:
<div ng-show="isshow" class="inline-block">
<div class="revise-radio" ng-repeat="x in types track by $index">
<input ng-class type="radio" name="typename" ng-value="$index" ng-model="type" >{{x.type}}
</div>
</div>
使用ng-repeat指令迭代输出input时,无法取值
原因:ng-repeat指令会产生一个新的scope子域,子scope属性会覆盖父scope同名属性,angularjs中子scope只会继承父scope的对象
解决方法:ng-model绑定为非基本数据类型,即对象即可解决:ng-model="params.type"
拓展:若非要使用基本数据类型,有以下2个方法:
1,在子scope中使用$parent.parentPrimitive,阻止子scope创建自己的属性
2,在父scope中定义一个函数,让scope调用,传递原始数据类型的参数给父级,更新父级scope的属性(注:并不总是有效)
评论