2015-05-14 73 views
0

我很好奇如何为单选按钮组的<input type="radio">父级div添加班级?AngulaJS为活动单选按钮添加班级到父级

的代码是下面和JSFiddle is here

HTML:

<div class="bd"> <input type="radio" ng-model="value" value="foo" ng-change='newValue(value)'></div> 
     <div class="bd active"><input type="radio" ng-model="value" value="bar" ng-change='newValue(value)'></div> 
      <div class="bd"><input type="radio" ng-model="value" value="baz" ng-change='newValue(value)'> </div> 
<hr> 

</div> 

JS:

var myApp = angular.module('myApp',[]); 

function MyCtrl($scope) { 
    $scope.value= 'foo'; 

    $scope.newValue = function(value) { 
     console.log(value); 
    } 
} 

CSS:

.bd { 
    border:1px solid red; 
    width:100px; 
    float:left; 
} 
.active{ 
    border:1px solid green; 
} 

回答

1

你可以做到这一点与纳克级的指令:

<div ng-class="{'active': value=='foo'}" ...> 

这里是更新小提琴:http://jsfiddle.net/6urevw2t/2/

希望它能帮助,

问候