5

Below is the code to list toggle buttons in which I want to set the first toggle button to be on and the rest off..

<ion-view view-title="Choose language">
  <ion-content>
    <div class="list"> 
      <ion-toggle ng-repeat="item in lists" ng-model="item.checked"   
        ng-checked="item.checked">
        {{ item.name }}   
      </ion-toggle>
    </div>
  </ion-content>
</ion-view>

   $scope.lists= [
                { name: 'List1' },
                { name: 'List2' },
                { name: 'List3' },
            ];

I tried by giving $scope.item.checked='List1' but didn't work.Any possible solutions for this issue..

forgottofly
  • 2,729
  • 11
  • 51
  • 93

3 Answers3

5

For the toggle to be always ON by default respective of the model:

<ion-toggle item-right (ionChange)="someMethod($event.checked)" checked="{{somebooleanmodel}}"></ion-toggle>
Uzer Pathan
  • 51
  • 1
  • 1
3

In your markup the item in the repeat is the object in the lists array.

Try this. Replace the $scope.lists by this object.

$scope.lists = [
    { name: "List1", checked: false },
    { name: "List2", checked: true },
    { name: "List3", checked: false }
  ];

Hope it helps.

M. Junaid Salaat
  • 3,765
  • 1
  • 23
  • 25
0

For the toggle to be always ON by default irrespective of the model, set:

<ion-toggle ng-checked="true" ng-model="someModel">
  {{expression}}   
</ion-toggle>
Slartibartfast
  • 1,592
  • 4
  • 22
  • 33