javascript - AngularJS: Select radio button by clicking on outer element -
i have following code inside angularjs app:
<div class="radio input-group-addon"> <label> <input type="radio" name="radio1" value="foobar" ng-model="mymodel" /> label </span> </div> the outer div 100% background color. want able make whole area (the whole div container) clickable. tried ng-click handler on div this:
<div class="radio input-group-addon" ng-click="selectradio($event)"> <label> <input type="radio" name="radio1" value="foobar" ng-model="mymodel" /> label </span> </div> the selectradio($event) method looks this:
$scope.selectradio = function($event) { var radio = $(event.currenttarget).find("input[type='radio']"); radio.prop("checked", true); radio.trigger("change"); } unfortunately, doesn't trigger change on mymodel. there way trigger "model-bind-change" event (don't know right term discribe this), update model of radio button?
and furthermore wondering, if there more angular-way achieve this?
something should solve it:
<div class="radio input-group-addon" ng-click="mymodel = 'foobar'"> <label> <input type="radio" name="radio1" value="foobar" ng-model="mymodel" /> label </label> </div>
Comments
Post a Comment