当一个单选按钮是在NG-重复,当我在电台按钮,在div将被启用点击? [英] when a radio button is in ng-repeat when i click on radio button the div will be enable?
本文介绍了当一个单选按钮是在NG-重复,当我在电台按钮,在div将被启用点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面当我在电台按钮,请单击下面的div应禁用如果检查的单选按钮是等于在这里sj.But它不工作,如果我用NG-重复的单选按钮同样是工作,如果其static.Could任何一个帮我出什么错误,我在这里做?
< DIV NG-应用=plunker>
< DIV CLASS =包装NG-控制器=MyCtrl>
< H1>您好!有< / H1>
< P>按单选按钮来更改内容<!/ P>
<形式为GT;
< DIV NG重复=S颜色>
<输入ID =第一类型=电台NAME =内容NG模型=内容值=s.name> {{s.name}}
< BR />< / DIV>
< /表及GT; < DIV CLASS =包装>
< p NG秀=内容=='SJ'>这是第一个内容<!/ P>
< / DIV>
< / DIV>
< / DIV><脚本>
VAR应用= angular.module('plunker',[]);app.controller('MyCtrl',函数($范围){
$ scope.color = [{名:SJ},{名:asfdsaf},{名:sdfsadf},{名:自卫队}];
});< / SCRIPT>
解决方案
事情夫妻俩都错过了。
- 更改您
NG-模型
范围变量指向其父像NG-模式=$ parent.content
而不是NG-模式=内容
,因为NG-重复创建从当前范围子范围。 - 使用
NG-值
,而不是为范围的变量绑定到它值
属性。
HTML
<形式为GT;
< DIV NG重复=S颜色>
<输入ID =第一类型=电台NAME =内容NG模型=$ parent.contentNG值=s.name> {{s.name}}
< BR />
< / DIV>
< /表及GT;
Here when i click on radio button the following div should be disable if the checked radio button is equals to sj.But here its not working if i use ng-repeat for radio button same is working if its static.Could any one help me out what is the mistake i have done here?
<div ng-app="plunker">
<div class="wrap" ng-controller="MyCtrl">
<h1>Hello there!</h1>
<p>Push the radio buttons to change the content!</p>
<form>
<div ng-repeat="s in color">
<input id="first" type="radio" name="content" ng-model="content" value="s.name">{{s.name}}
<br/></div>
</form>
<div class="wrapper">
<p ng-show="content == 'sj'">This is the first content!</p>
</div>
</div>
</div>
<script>
var app = angular.module('plunker', []);
app.controller('MyCtrl', function($scope) {
$scope.color = [{"name":"sj"},{"name":"asfdsaf"},{"name":"sdfsadf"},{"name":"sdf"}];
});
</script>
解决方案
Couple of things are missed
- Change you
ng-model
scope variable to point its parent likeng-model="$parent.content"
instead ofng-model="content"
, because ng-repeat creates child scope from current scope. - Use
ng-value
instead ofvalue
attribute for binding scope variable to it.
HTML
<form>
<div ng-repeat="s in color">
<input id="first" type="radio" name="content" ng-model="$parent.content" ng-value="s.name">{{s.name}}
<br/>
</div>
</form>
这篇关于当一个单选按钮是在NG-重复,当我在电台按钮,在div将被启用点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文