8

I want to implement spinner with loading controller in ionic3 . I have implemented simple loading controller . how to do it? thanks in advance.

My current loader

enter image description here

I want something like this

enter image description here

Sampath
  • 63,341
  • 64
  • 307
  • 441
Niraj
  • 1,039
  • 1
  • 10
  • 14
  • http://ionicframework.com/docs/components/#loading – Sampath Sep 19 '17 at 19:10
  • I want something like as in "Show Custom" option , but unable to find source code. I have already implemented simple loader . https://ionicframework.com/docs/api/components/loading/LoadingController/ – Niraj Sep 19 '17 at 19:17
  • What is the issue there? Can you show the `code`? – Sampath Sep 19 '17 at 19:19
  • @Sampath there is no any issue , i just want to improve user experience. i have uploaded images of my current loader and what i want. i am unable to find what attributes to add here to get that. what to do within it- let loader = this.loading.create({ content: 'Loading Products...', }); – Niraj Sep 19 '17 at 20:06
  • 1
    Check this answer https://stackoverflow.com/a/44111306/1116320 – HaseebR7 Sep 19 '17 at 23:35
  • that was helpful , but unable to implement – Niraj Sep 21 '17 at 07:14

2 Answers2

9
presentLoadingCustom() {
    let loading = this.loadingCtrl.create({
      spinner: 'hide',
      content: `<img src="assets/img/gif.gif" />`,
      duration: 5000
    });

    loading.onDidDismiss(() => {
      console.log('Dismissed loading');
    });

    loading.present();
  }

inside image tag give some gif image and it works fine i have tested it

Output imag

Mohan Gopi
  • 7,606
  • 17
  • 66
  • 117
3

Ionic 2&3 has a built in service for blocking UI and giving visual feedback to users when the app is executing some time consuming activity on background such as loading data from a remote database .

You simply use the LoadingController which is available from ionic-angular module

So start by importing LadingController

import { LoadingController } from 'ionic-angular';

Then create a property and inject it on the class constructor

export class LoginPage {
loading: any;
constructor(public loadingController:LoadingController){...}
}

and create loading indicator in method from where requesting the data

login() {
    this.loading = this.loadingController.create({ content: "Logging in ,please wait..." });
    this.loading.present();
    this.errors = "";
    //api service call
    this.authService.postData(this.userData, 'api/account/login').then((result) => {
      this.responseData = result;
      if (result != null) {
        this.loading.dismissAll();
        //console.log(result);
        this.common.setLocalData(DataKey.User.toString(), result);

        this.navCtrl.push(TabsPage);
      }
      else {
        this.loading.dismissAll();
        this.errors = "Nope, Try Again";
      }
    }, (err) => {
      this.loading.dismissAll();
      this.errors = "Nope, Try Again";
      // Error log
    });
  }

When you are successfully logged in the method dismissAll() hides the loading indicator so you can continue interacting with your app normally.

Manveer Singh
  • 351
  • 6
  • 27