Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamically set checked state in radio button in Angular js

I am working with MEAN Stack and I have a form which is included radio

Button which is submitted successfully Now what I want is to edit the record. I want is that the record radio button should be checked according to database value.

How to do that.

my edit form is:-

 <form id = "expensesCreate" class="form-horizontal" name="myForm">
    <div class="form-group">
                            <label for="Phone_no" class="col-sm-3">Address</label>
                            <div class="col-sm-4 @if($errors->has('Phone_no')) has-error @endif">
                                <input class="form-control input-sm" placeholder="" autocomplete="off" id="address"  name="address" ng-model="address"  type="address" value ="{{registeruser.address}}" required>
                                <p class="error" ng-show=" myForm.password.$touched && myForm.password.$error.required" >Address is required.</p>
                            </div>
                        </div>

                         <div class="form-group">
                            <label for="Phone_no" class="col-sm-3">Sex</label>
                            <div class="col-sm-4 @if($errors->has('Phone_no')) has-error @endif">
                                Male <input type="radio"  ng-model="sex" value="Male" >
                                FeMale<input type="radio" ng-model="sex" value="Female">

                            </div>
                        </div>
</form>

if sex is male of a particular record into database how to checked or selected male radio button.

like image 356
Shahzad Intersoft Avatar asked Oct 29 '22 15:10

Shahzad Intersoft


1 Answers

You can evaluate the sex property to truthy in your view like so:

<td><input type='radio' ng-checked="p.sex=='male'"></td>
<td><input type="radio"  ng-checked="p.sex=='female'" ></td>

Hope it helps.

like image 62
Jax Avatar answered Nov 15 '22 06:11

Jax