Ionic Switch Operation

From WikiOD

Ionic switch operation[edit | edit source]

In the following example, different values ​​are displayed by switching different switches checked, true is on, and false is off.

HTML code[edit | edit source]
 <ion-header-bar class="bar-positive">

   <code><h1 class="title">Switch switch</h1></code>

 </ion-header-bar>

 <ion-content>
<div class="list">
  <code><div class="list"></code>

         <code><div class="item item-divider"> </code>
<div class="item item-divider">
      Settings

  <code></div></code>
</div>
    <ion-toggle ng-repeat="item in settingsList"
 <code> </code>              ng-model="item.checked" 
 <code> </code>              ng-checked="item.checked">
 <code> </code> <code>{{item.text}}</code>
 <code> </code>  </ion-toggle>
    
<div class="item">
    <code><div class="item"></code>

    	<!-- Use the pre tag to display more beautifully-->

       <code><div ng-bind="settingsList | json"></div></code> 

    <code></div></code>

     <code><div class="item item-divider"> </code>
</div><div class="item item-divider">
      Notifications

   <code></div></code>
</div>
    <ion-toggle ng-model="pushNotification.checked"
                ng-change="pushNotificationChange()">
      Push Notifications
    </ion-toggle>
    
<div class="item">
  <code><div class="item"></code>

    	<!-- Use the pre tag to display more beautifully-->

      <code><div ng-bind="pushNotification | json"></div></code> 

    <code></div></code>
</div>
    <ion-toggle toggle-class="toggle-assertive"
                ng-model="emailNotification"
                ng-true-value="Subscribed"
                ng-false-value="Unubscribed">
      Newsletter
    </ion-toggle>
    
<div class="item">
 <code><div class="item"></code>

   	<!-- Use the pre tag to display more beautifully-->

       <code><div ng-bind="emailNotification | json"></div></code> 

     <code></div></code>

      <code></div></code>
</div></div>
 </ion-content>

Due to the conflict of pre tags, the pre in the example has been replaced with a div tag. You can check the details in "Try it out".

JavaScript code[edit | edit source]
 angular.module('ionicApp', ['ionic'])

 .controller('MainCtrl', function($scope) {

  $scope.settingsList = [
    {text: "Wireless", checked: true },
    {text: "GPS", checked: false },
    {text: "Bluetooth", checked: false}
  ];

  $scope.pushNotificationChange = function() {
    console.log('Push Notification Change', $scope.pushNotification.checked);
  };
  
  $scope.pushNotification = {checked: true };
  $scope.emailNotification ='Subscribed';
  

 });
css code:[edit | edit source]
 body {

  cursor: url('http://www.phpxs.com/try/demo_source/finger.png'), auto;

 }