Id

Improve this doc

The id attribute is an easy way to identify unique components in an app and access them no matter where in the UI hierarchy you are. For example, this makes toggling a global side menu possible from any place in the application.

Directive

selector: [id]

Usage

To give any component an ID, simply set its id property:

<ion-checkbox id="myCheckbox"></ion-checkbox>

To get a reference to the registered component, inject the IonicApp service:

constructor(app: IonicApp) {
  this.app = app
}

ngAfterViewInit() {
  var checkbox = this.app.getComponent("myCheckbox");
  if (checkbox.checked) {
    console.log('checkbox is checked');
  }
}

NOTE: It is not recommended to use ID's across Pages, as there is often no guarantee that the registered component has not been destroyed if its Page has been navigated away from.

API

Native

General