URL: https://www.progressiverobot.com/ionic-intro-slider/

The <^>ion-slides<^> component available with Ionic 2 makes it easy to create an intro slider for your app. This can be used as a quick tutorial on how to use the app or a showcase of the features.

Implementing the intro slider is very straightforward, with the only part that can be a bit more tricky being a way to show that intro slider only once, the first time the app is opened. For that, we'll use Ionic Storage.

Adding an Intro Page

slider illustration for: Adding an Intro Page

You can use the Ionic CLI to add the Intro page:

				
					
$ ionic g page Intro

				
			

Then import the new page in your app module and add it to the declarations and entryComponents. Also make sure that you're importing <^>Storage<^> and including it in the list of providers:

				
					
[label app.module.ts]

// ...

import { Storage } from '@ionic/storage';

import { IntroPage } from '../pages/intro/intro';





				
			

The Home Page Component

In this example <^>Home.ts<^> is our default home page component, where users will be taken after viewing the intro slider or once they've seen the intro slider once already.

Go ahead and import the Intro page, <^>NavController<^> and <^>Storage<^> in your home page component. You should also inject NavController and Storage in the constructor:

				
					
[label home.ts]

// ...

import { NavController } from 'ionic-angular';

import { Storage } from '@ionic/storage';

import { IntroPage } from '../pages/intro/intro';



constructor (public navCtrl: NavController, public storage: Storage) {}



				
			

And inside the home page component class let's use Ionic's <^>ionViewDidLoad<^> hook to check if an <^>intro-done<^> key has been set in storage. If it hasn't, we set it so that the intro page doesn't get shown again and then use <^>NavController<^> to show the intro page with our slider. Notice how we use <^>navCtrl.setRoot<^> instead of <^>navCtrl.push<^>, to make sure that our intro page doesn't get a back button:

				
					
[label home.ts]

ionViewDidLoad() {

 this.storage.get('intro-done').then(done =&gt; {

 if (!done) {

 this.storage.set('intro-done', true);

 this.navCtrl.setRoot(IntroPage);

 }

 });

}

				
			

Intro Page with Slider Component

The setup work is now done and we can focus on the slider and the intro page itself. We define the slider with the <^>ion-slides<^> component and the individual slides with <^>ion-slide<^>:

				
					
&lt;ion-content&gt;

 &lt;ion-slides pager="true" parallax="true" padding&gt;



 &lt;ion-slide&gt;

 &lt;img src="assets/img1.svg"&gt;

 &lt;h1&gt;Welcome to my app!&lt;/h1&gt;

 &lt;/ion-slide&gt;



 &lt;ion-slide&gt;

 &lt;img src="assets/img2.svg"&gt;

 &lt;h1&gt;All of the features&lt;/h1&gt;

 &lt;p&gt;Here's what you can do with the app...&lt;/p&gt;

 &lt;/ion-slide&gt;



 &lt;ion-slide&gt;

 &lt;img src="assets/img3.svg"&gt;

 &lt;h1&gt;Get started now!&lt;/h1&gt;

 &lt;button ion-button outline small (click)="navHome()"&gt;

 Start using the app

 &lt;/button&gt;

 &lt;/ion-slide&gt;



 &lt;/ion-slides&gt;

&lt;/ion-content&gt;

				
			

The <^>ion-slides<^> component can take a bunch of different options. Here we set <^>pager<^> and <^>parallax<^> to true. Pager adds small bullet at the bottom of the slides to show the number of slides and the currently active slide. You can refer to the official documentation for a list of all the options.

Note that the way the options are passed to <^>ion-slides<^> is new since Ionic 2 RC5, and will be the way to go forward.

Notice how we don't have any navbar on the page, to let the slider take the full height of the page.

Going Back to the Home Page

The button on the last slide calls a <^>navHome<^> method that will set the Home page back as the root page. Simply define the method in the Intro page component class, making sure that NavController has been imported and injected in the constructor and that the Home page is imported:

				
					
[label intro.ts]

// ...

import { NavController } from 'ionic-angular';

import { HomePage } from '../home/home';



// ...

export class IntroPage {

 constructor(public navCtrl: NavController) {}



				
			

A Touch of Style

Once final touch, the pager bullets for the slider are blue by default, so here we changed their color with a small addition to the Sass file of the Intro page:

				
					
[label intro.scss]

page-intro {

 .swiper-pagination-bullet-active {

 background: #A713E8;

 }

}