Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
166
rated 0 times [  168] [ 2]  / answers: 1 / hits: 7057  / 10 Years ago, tue, march 18, 2014, 12:00:00

I have the following code inside an angularjs app:



    <div class=radio input-group-addon>
<label>
<input type=radio name=radio1 value=foobar ng-model=myModel />
my label
</span>
</div>


The outer div is 100% with a background color. Now I want to be able to make the whole area (the whole div container) clickable. I tried it with an ng-click handler on the div like this:



    <div class=radio input-group-addon ng-click=selectRadio($event)>
<label>
<input type=radio name=radio1 value=foobar ng-model=myModel />
my label
</span>
</div>


The selectRadio($event) method looks like this:



$scope.selectRadio = function($event) {
var radio = $(event.currentTarget).find(input[type='radio']);
radio.prop(checked, true);
radio.trigger(change);
}


Unfortunately, this doesn't trigger a change on myModel. Is there a way to trigger a model-bind-change event (don't know the right term to discribe this), to update the model of my radio button?



And furthermore I was wondering, if there is a more angular-way to achieve this?


More From » jquery

 Answers
14

Something like this should solve it:



<div class=radio input-group-addon ng-click=myModel = 'foobar'>
<label>
<input type=radio name=radio1 value=foobar ng-model=myModel />
my label
</label>
</div>

[#46759] Monday, March 17, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrence

Total Points: 120
Total Questions: 115
Total Answers: 87

Location: England
Member since Fri, May 22, 2020
4 Years ago
;