Change the toggled state of an item based on another toggled event?


I have a set of “permissions” for DJ’s on a radio broadcasting channel, some have conditions for example:

History Report - (currently toggled as false)
Listener Statistics - (currently toggled as true)


<ion-label>History Report</ion-label>
<ion-toggle [(ngModel)]=“data.historyReport”></ion-toggle>

<ion-label>Listener Statistics</ion-label>
<ion-toggle [(ngModel)]=“data.listenerStatistics”></ion-toggle>

Trying to implement this with a basic javascript switch

switch (this.checkPermissions(djPermission.ResourceAccess.FlatPermissions, resourcePermissions.HistoryReport)) {
case true:
this.stationListenerDisabled = true;
this.stationListenerDisabled = false;

The switch in this case does the disabling of the toggled items, but my code would be in there to change to toggled states between the items.

If I change History Report to true, I am already disabling Listener Statistics, but I need to change the state to false and back to true if History is false again.


My code is generated by Angular on the Front End side dynamically.
Done with Ionic / Typescript / Javascript

If that makes any sense…

Please any ideas? I have tried targeting child nodes and attribute nodes etc. but it gets nasty after a while.


Seeing the code you have currently would probably be of use to anybody trying to help.


Well it is a basic ionic ion-toggle component, which needs to change another toggled items value. Not sure how all the code would make that simpler. Do you want me to post the code?


There is nothing basic whatsoever about mixing jQuery and Angular, nor “targeting child nodes and attribute nodes” in an Angular application, so I worry that what you have now is relatively esoteric and unidiomatic.


Perhaps this will help you a bit more… @rapropos (Updated description)

PS: Based on your comments, it really has nothing to do with the libraries I am using.
More on what ion-toggles can and cannot do, or how to approach the above said scenario.


The ordinary Angular way to do any of this (including the disabling) is to take advantage of property binding. See this example:

      <ion-toggle [(ngModel)]="state" [disabled]="!enabled"></ion-toggle>

    <button ion-item (click)="toggleState()">
      <ion-label>toggle state</ion-label>

    <button ion-item (click)="toggleEnabled()">
      <ion-label>toggle enabled</ion-label>
  state = false;
  enabled = true;

  toggleState(): void {
    this.state = !this.state;

  toggleEnabled(): void {
    this.enabled = !this.enabled;