Issue
I have what is basically a radio type selection, but because I wanted it to look more like a selection grid I opted to make a input type button instead and triggering a function on click, but I have a problem. ng-model won't bind the value of the button I clicked to the controller part, and I know it works just fine as a radio button.
What's the quickest way to solve this? I'm assuming there's an easier way than to redefine the css of a radio button... Especially since it's all done except linking the value on click with the variable itself.
The section in question:
<div class="aquipartners" id="aquipartnersID">
<input ng-repeat="partner in partners" align="center" type = 'button' class = "aquipartnernamebutton" id='aqui{{partner.name.PT}}' value='{{partner.name.PT}}' ng-model='newaquisubmission.part' onclick ='partnerselect()'>
</input>
</div>
And on the JS side:
function partnerselect(){
var scopepartnerbutton = $('#subtitleid').scope().newaquisubmission.part;
alert(scopepartnerbutton);
if(scopepartnerbutton !== ""){
//the stuff I want to do, I added the if as a safeguard while I program everything
}
};
Solution
as @georgeawg said, use ng-click. make sure you have this on your controller:
$scope.partnerselect = partnerselect
and partnerselect should be declared like this:
function partnerselect(value) {
if($scope.newaquisubmission.part){
$scope.newaquisubmission.part = value; //Assuming this is what you want to do..
}
}
On your view:
<div class="aquipartners" id="aquipartnersID">
<input ng-repeat="partner in partners" align="center" type = 'button' class = "aquipartnernamebutton" id='aqui{{partner.name.PT}}' value='{{partner.name.PT}}' ng-click ="partnerselect(partner.name.PT)">
</input>
</div>
Answered By - John Ephraim Tugado
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.