Details Arrow: Ionic 2


Today lets see how we can add details arrow or the right arrow icon to our list items in Ionic 2.

ion-item-right-arrow-icon

Ionic uses modes to customize the look of components. Each platform has a default mode, but this can be overridden. For example, an app being viewed on an Android platform will use the md (Material Design) mode. The < ion -app > tag(in index.html) will have class=”md” added to it by default and all of the components will use Material Design styles:

index.html

< ion-app class="md">

Default Modes used on different platforms
ios devices – ios mode.
android devices – md(Material Design) mode.
windows devices – wp mode.

ion-list item Right Arrow Icon: Ionic 2


[youtube https://www.youtube.com/watch?v=gCXS6gRuyvk]

YouTube Link: https://www.youtube.com/watch?v=gCXS6gRuyvk [Watch the Video In Full Screen.]



In ios mode, buttons and anchor elements with ion-item attribute will display right arrow icon by default. If you want to remove this right icon you should add detail-none attribute to your elements.

Note:
1. For removing right arrow icon use detail-none attribute on your elements.
2. To add right arrow icon use detail-push attribute on your elements.

If the arrow still doesn’t display, you need to overriding some variables inside src/theme/variables.scss file.

For iOS Mode: iOS devices

$item-ios-detail-push-show: true;

For md mode: android devices

$item-md-detail-push-show: true;

For wp mode: Windows Devices

$item-wp-detail-push-show: true;

Important:
If you are previewing or testing your ionic 2 application using Chrome browser on Windows machine, then set variable $item-wp-detail-push-show also to true or else simply set the one applicable to your target device.

src/pages/home/home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
 
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  companies: any;
  constructor(public navCtrl: NavController) {
    this.companies = [
      {name: 'Microsoft', code: 1},
      {name: 'Apple', code: 2},
      {name: 'Google', code: 3},
      {name: 'Oracle', code: 4}
    ];
  }
}

src/pages/home/home.html

  < ion-list no-lines>
    < ion-item *ngFor="let company of companies" detail-push>
      {{company.name}}
    < /ion-item>
  < /ion-list>

For explanation of above code please watch: Basics of Page Component: Ionic 2 video tutorial.

Remove Lines From ion-list items
Add no-lines attribute to ion-list tag to remove the default linings from the list items displayed on the view.

Leave a Reply

Your email address will not be published. Required fields are marked *