javascript - AngulaJS add a class to parent for active radiobutton -
i'm curious how add class parent div <input type="radio"> group of radio buttons?
the code below , jsfiddle 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; }
you can ng-class directive:
<div ng-class="{'active': value=='foo'}" ...> here fiddle updated: http://jsfiddle.net/6urevw2t/2/
hope helps,
regards
Comments
Post a Comment