Set default switch to switch in switch

Below is the code for the list of toggle buttons in which I want to set the first toggle button so that it is on and the rest is 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 to provide $ scope.item.checked = 'List1' , but did not work. All possible solutions to this problem ..

+4
source share
2 answers

In your item markup in repetition is an object in the lists array.

Try it. Replace $scope.lists with this object.

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

Hope this helps.

+3
source

To always turn on the switch by default, regardless of model, set:

 <ion-toggle ng-checked="true" ng-model="someModel"> {{expression}} </ion-toggle> 
0
source

All Articles