Nested promise not working with storage


#1

had some strange problem occurring in Android 4.4

    ionViewDidLoad() {
    let loader = this.loadingCtrl.create({
      content: "Please wait...",
      });
      loader.present();

    this.authService.getAccessToken().then((accessToken) => { //1st promise returned the access token and working fine
        this.accessToken = accessToken;
        this.authService.getUserDetails().then((userDetails)=>{ //2nd promise not working on first load
            this.user_info=userDetails;
          
        this.courseService.getAllCourses(this.accessToken).then((foundCourse)=>{ // 3rd promise 
            this.foundCourse=foundCourse;
            loader.dismiss();
          });
        });
        
      });
    
  }

loader didn’t dismiss on 4.4.
however everything seems to be working fine in 5.1 Lolipop.

Any ideas how to fix this?


#2

@ionicteam please help me on this as I am still not able to resolve


#3

Aren’t nested Promises almost always code smell? My suggestion is that you flatten the Promise chain and see if that resolves the problem. Can you use .all() ? It looks as though step 3 depends on steps 1 and 2, but steps 1 and 2 could be executed in parallel.


#4

Hi,
Thanks for the suggestions…
However, even if I remove the 2nd promise the 3rd promise is still not working…and its only happening in 4.4.x versions of android.
If nested promise is the core problem then why its working on 5.0 and above?