2015-05-14 107 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/

希望它能幫助,

問候