0

I am editing User Form. I send the data from controller to the edit view using $scope object for editing form. The data is look like this:

        $scope.changeUser = [

          {

                id: 1,
                username: 'Ramesh',
                password: 'Ramesh1@23',
                role: 'admin',
                active: 'no'
            }
    ];
       <div class="form-group">
                        <label class="control-label col-md-3">Action</label>
                        <div class="col-md-4">
                            <div class="radio-list">
                                <label class="radio-inline">
                                    <input type="radio" name="optionsRadios2"  data-ng-model="changeUser.active"  value="yes"/>
                                    Yes
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="optionsRadios2" data-ng-model="changerUser.active" value="no"/>
                                    No
                                </label>
                            </div>
                        </div>

                    </div>

When edit form get {{changeUser.action}} than, I have to checked the radio button accordingly. As like when action=='no' the radio button with name no should be automatically checked as we did using checked value=no in the html. I have to write the ng-if conditions seeing the action value.

1 Answer 1

1

You are missing the index of changeUser array in your ng-model.

    <div class="form-group">
        <label class="control-label col-md-3">Action</label>
        <div class="col-md-4">
            <div class="radio-list">
                <label class="radio-inline">
                    <input type="radio" name="optionsRadios2" data-ng-model="changeUser[0].active" value="yes" />
                    Yes
                </label>
                <label class="radio-inline">
                    <input type="radio" name="optionsRadios2" data-ng-model="changeUser[0].active" value="no" />
                    No
                </label>
            </div>
        </div>    
    </div>

See the Plnkr

Sign up to request clarification or add additional context in comments.

8 Comments

This is not the answer i am looking for. I am asking about doing checked value=no or checked value=yes according to the value get from @scope `action: yes or no'.
@user3789184 The above solution will work. Since the angular will compare the value of 'ng-model' with the value assigned to radio. If matched the respective radio will be shown checked.
But, When i edit the form, only one data will be on $scope. So, that, I cannot use ng-repeat in this case.
If you don't want to use ng-repeat, remove 1st div and pass the data-ng-model as changeUser[0].active to both the radio inputs.
@user3789184 Updated my answer. Have a look.
|

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.