How to use UI Components of Ionic Angular


Ionic UI Components are amazing and are so many varieties one. In many cases, you can use components along with the official documentation. But in documentation, it includes contents that are lack of detail or are difficult to understand for me.
So this article is about Ionic UI Components and relevant way to mark up. TBA.


The slide UI is often used. It’s especially important to get a selected index that of displayed slide.

<ion-slides #slides [options]="slideOpts" (ionSlideDidChange)="slideDidChange($event)">

import {
  Component, ViewChild
} from '@angular/core';
import {IonSlides} from "@ionic/angular";

export class TestPage {
  @ViewChild('slides', { static: true }) slider: IonSlides;
  slideOpts = {
    initialSlide: 0,
    speed: 400

  constructor() { }

  slideNext() {
  slidePrev() {
  // Get selected slide index
  async slideDidChange(event) {
    const i = await this.slider.getActiveIndex()


Call showPicker to show up a picker. Especially, take care for how to set a default value to picker.

import { PickerController } from '@ionic/angular';
export class AppComponent {

  constructor(private pickerCtrl: PickerController) {}
  async showPicker() {
    let opts = {
      buttons: [
          text: '',
          role: 'cancel'
          text: 'OK'
      columns: [
          name: 'number',
          selectedIndex: 0, // set index of default value
          options: [
            { text: '1', value: 1 },
            { text: '2', value: 2 },
            { text: '3', value: 3 }
    let picker = await this.pickerCtrl.create(opts);
    picker.onDidDismiss().then(async data => {
      let col = await picker.getColumn('number');
      console.log(col.selectedIndex) // selected index


The way of filling width or height, for example “match_parent" or “fill_parent" in Android, and operation with storyboard in iOS, does not exist in ionic HTML/CSS.
For example the following. Need to set “second" height for the rest of the screen height.


    <div class="first">first</div>
    <div class="second">second</div>


.first {
    height: 50px;
.second {
    height:calc(100vh - 50px);

But that way is based on that “first" height is not variable and other element doesn’t exist.
If you want to fill the variable height, the following is a good way.

ion-content {
  --overflow: hidden;
.first {
    height: 50px;
.second {
    padding-bottom: 9999px;
    overflow: hidden;

It set “second" height a value that is absolutely over parent size with huge padding, and disable scrolling. This might be an unreasonable way.

Color of ion-item

If you want to change border color or background color of ion-item, add the following to css.

ion-item {
  --border-color: #fff;