2

i am new to angularjs and javascript,I am having a list of radio buttons and have to make some of them selected,so can anybuddy please tell me how to achieve this?I tried ng-value=true with no luck,my code is as below:

<ons-list-item modifier="tappable"  ng-repeat="area in vm.AreaList" >
    <label class="radio-button radio-button--list-item line-h45">
        <input type="radio"  ng-bind="area.name"  ng-model="vm.selectedArea" name="area" ng-value="area.code" >
        <div class="radio-button__checkmark radio-button--list-item__checkmark">

        </div>
        {{area.name}}
    </label>
</ons-list-item>
1

3 Answers 3

1

you can do something like this in your controller:

 $scope.results = {
      favorites: [{
        id: "WatchList1",
        title: "WatchList1"
      }, {
        id: "WatchList2",
        title: "WatchList2"
      }, {
        id: "WatchList3",
        title: "WatchList3"
      }]
    };

$scope.selectedRow = {
  id: 'WatchList2'
};

$scope.event = {
  type: {
      checked: true
  }
}

and your html:

<div>
  <div ng-repeat="row in results.favorites">
  <input type="radio" ng-model="selectedRow.id" value="{{ row.id }}" style="opacity: 1;" class="pointer" />
  <span>{{ row.title }}</span>
  </div>
</div>

Single box

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

Comments

1

You should use ngChecked for that.

https://docs.angularjs.org/api/ng/directive/ngChecked

    <ons-list-item modifier="tappable"  ng-repeat="area in vm.AreaList" >
        <label class="radio-button radio-button--list-item line-h45">
            <input type="radio"  ng-bind="area.name"  ng-model="vm.selectedArea" name="area" ng-value="area.code" 
                 ng-checked="true">
            <div class="radio-button__checkmark radio-button--list-item__checkmark">
            </div>
            {{area.name}}
        </label>
    </ons-list-item>

Comments

-1

Only one radio button can be selected at a time.

If you want multiple selected items, then use checkbox and to select, make model value equal to value attribute.

3 Comments

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
answer does not mean that it must be some piece of code. Isn't it?
No, but the question is how to set a radio button as "selected".

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.