0

I'm trying to make a work a simple task without lucky, I'm trying to check an input radio by clicking on a button. Each input radio as their button. How do you achieve that in angular way?

<button class="btn btn-primary">

        <input type="radio" ng-model="color" value="1">

</button>


<button class="btn btn-primary">

        <input type="radio" ng-model="color" value="2">

</button>

<button class="btn btn-primary">

        <input type="radio" ng-model="color" value="3">

</button>

How you can see I put the input inside the element button, if you have different thoughts please correct me.

2
  • Why not just check the radio by clicking on the radiobutton? Commented Dec 2, 2014 at 18:44
  • Correct, i tried to that and it works but the problem is that angular validation give me that value as required even if I checked it with Jquery prop function. Commented Dec 2, 2014 at 18:45

2 Answers 2

1

Set the associated ng-model equal to the value of the radio you want selected:

<button class="btn btn-primary" ng-click="color = 1">
    <input type="radio" name="radioGroup" ng-model="color" value="1">
</button>
Sign up to request clarification or add additional context in comments.

Comments

1

Use <label> and style it as button:

<label class="btn btn-default"> Button 1
  <input type="radio" ng-model="color" value="1">
</label>

<label class="btn btn-default"> Button 2
  <input type="radio" ng-model="color" value="2">
</label>

and add css to hide the input[type="radio"].

Not everything needs Angular.

2 Comments

Wow, your solution is clever. I would like to accept your answer for the cleanest way to achieve it. But because is an angular related question I will accept that one above. But keep in mind I really appreciated this.
@Fabrizio, when you have a hammer, every problem looks like a nail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.