Ionic2: ion-toggle not toggling in android


#1

I have this ionic2 modal content:

<ion-toolbar class="android-attr" primary>
  <ion-title>
    Search Settings
  </ion-title>
  <ion-buttons start>
    <button (click)="dismiss()">
      <span primary showWhen="ios">Cancel</span>
      <ion-icon name='close' showWhen="android"></ion-icon>
    </button>
  </ion-buttons>
</ion-toolbar>
<ion-content class="has-header">
  <ion-list>
    <ion-item>
      <h2>Search by tags</h2>
      <p>I've had a pretty messed up day. If we just...</p>
      <p>I've had a pretty messed up day. If we just...</p>
      <ion-icon name="trash" item-right></ion-icon>
    </ion-item>
    <ion-item>
      <ion-label>Use my current location</ion-label>
      <ion-toggle checked="true"></ion-toggle>
      <h3>Don't Know What To Do!</h3>
    </ion-item>
    <ion-item>
      <p>I've had a pretty messed up day. If we just...</p>
    </ion-item>
  </ion-list>
  <div padding>
    <button primary block>Apply</button>
  </div>  
</ion-content>

Problem is here neither ion-toggle nor ion-checkbox toggling in android if simply touch it. I have simply added to html.


#2

is it submits the form?.. in ios ion-toggle submits the form


#3

it is exactly as i have shown the code. it not submitting anything as shown in code


#4

ok. in my case when i click the toggle it try to submit the form.


#5

With Beta-1 I found the toggle and checkbox not working until I associated an ngModel to it.


#6

did you ever resolve this?

In the :
A) you need to define an ngModel="thisItem.checked"
B) use ng-checked=“thisItem.checked”, not 'checked’
C) if you need to fire something when the toggle is checked, use either ng-change=“fireSomething()” or ng-click=“fireSomething()”

In your controller define:
$scope.thisItem = { checked : false } // or true, depending on starting on/off state you want.
$scope.fireSomething = function () { … do something …} ;