Dhaval Marthak
Dhaval Marthak

Reputation: 17366

Binding one value to checkboxes

i am getting swallowed by an issue.

I have this code currently

<div ng-repeat="list in ConnectivityDetails">
            <div class="connectivity">
                <div class="title">
                    Disable Connectivity??</div>
                <div class="decision">
                    <p style="float: left;">
                        <input type="checkbox" ng-checked="list.Connectivity"/>
                        <label for="Yes">
                        </label>
                        &nbsp;&nbsp;<span class="spans">Yes</span>
                    </p>
                    <p>
                        <input type="checkbox" ng-model="list.Connectivity"/>
                        <label for="No">
                        </label>
                        &nbsp;&nbsp;<span class="spans">No</span>
                    </p>
                </div>
            </div>
</div>

Problem: I am getting both the text boxes checked though the returning object is having only one value, how to bind true (Yes) for the checkbox and false (NO) for the other?

My Object Contains this:

var data = [{PracticeID: "1",Connectivity: "true", LabKey: "2154879",PracticeKey: "ABNCJFUE", CloudServiceURL: "ABC215947"}]";

I want to bind Connectivity value to one of the checkboxes

Help! Thank you

Upvotes: 0

Views: 2819

Answers (1)

James Kleeh
James Kleeh

Reputation: 12228

Fiddle: http://jsfiddle.net/ymZdx/3/

So it should be:

           <p style="float: left;">
                <input type="checkbox" ng-model="list.Connectivity" />
                <label for="Yes">
                </label>
                &nbsp;&nbsp;<span class="spans">Yes</span>
            </p>
            <p>
                <input type="checkbox" ng-model="list.Connectivity" ng-true-value="false" ng-false-value="true" />
                <label for="No">
                </label>
                &nbsp;&nbsp;<span class="spans">No</span>
            </p>

Upvotes: 1

Related Questions