2016-08-22 15 views
6

मैं हाल ही में जोड़ा LoadingController इस तरह से उपयोग करने के लिए कोशिश कर रहा हूँ काम नहीं करता:आयोनिक 2 लोड हो रहा है नियंत्रक

let loading=this.load.create({ 
    content: "Connexion au serveur Migal en cours..." 
}); 

loading.present(); 

this.http.get(this.urlCheckerForm.value.migalUrl+'/action/MobileApp/URLChecker') 
    .map(res => res.json()) 
    .subscribe(
    data => this.newConnection(data,loading), 
    error => this.catchURLError(loading)); 

loading.dismiss(); 

असल में, मैं सिर्फ अपनी लोड हो रहा है पॉप में प्रदर्शित करने के लिए मेरा पेज लोड होने से पहले चाहते हैं, और इसे बाद में खारिज कर दें।

मैं Ionic 2 Documentation पर उदाहरण का पालन किया है, लेकिन यह सब पर काम करने के लिए ... प्रतीत नहीं होता

संपादित करें: लोड हो रहा है घटक भी दिखाई नहीं देता।

उत्तर

14

अपने कोड के साथ मुद्दा यह है कि आप http अनुरोध कर रहे हैं और फिर बुला है dismiss() लेकिन dismiss() विधि नहीं है http अनुरोध को समाप्त करने के लिए प्रतीक्षा करें। कृपया this plunker पर एक नज़र डालें।

कोड काफी आत्म व्याख्यात्मक है:

import { NavController, LoadingController } from 'ionic-angular/index'; 
import { Http, Response } from '@angular/http'; 
import { Component } from "@angular/core"; 
import 'rxjs/Rx'; 

@Component({ 
    templateUrl:"home.html" 
}) 
export class HomePage { 

    private users : Array<any> 

    constructor(private http: Http, private loadingCtrl: LoadingController) { 

    // Create the popup 
    let loadingPopup = this.loadingCtrl.create({ 
     content: 'Loading data...' 
    }); 

    // Show the popup 
    loadingPopup.present(); 

    // Get the data 
    this.http.get('https://jsonplaceholder.typicode.com/users') 
     .map((res: Response) => res.json()) 
     .subscribe(
     data => { 

      // I've added this timeout just to show the loading popup more time 
      setTimeout(() => { 
      this.users= data; 
      loadingPopup.dismiss(); 
      }, 1000); 

      // Should be just this: 
      // this.users= data; 
      // loadingPopup.dismiss(); 
     }, 
     err => console.error(err) 
    ); 

    } 
} 
+0

के अंदर http कॉल करना चाहते हैं यह एक आकर्षण की तरह काम करता है! :) आपके विवरण के लिये धन्यवाद। मैं असममित चीजों के बारे में भूल गया। –

+0

वहां गए, उस लॉल को किया। खुशी है कि मैं मदद कर सकता हूँ :) – sebaferreras

+1

लोड करने के बादPopup.dismiss(); अब आप इसका उपयोग नहीं कर सकते हैं। आइए हम कहें कि हमारे पास एक बटन है और जब भी उपयोगकर्ता उस पर क्लिक करता है तो आप लोडिंगपॉपअप दिखाना चाहते हैं, तो आपको लोडिंगपॉपअप को फिर से बनाना होगा। – Amare

0

आयनिक के अंतिम versione के लिए आप को संभालने के लिए ve खारिज घटना:

let loading = this.load.create({ 
    content: "Connexion au serveur Migal en cours..." 
}); 

loading.present(); 

loading.onDidDismiss().then(() => { 
    do thinks..... 
}); 
+0

अच्छा, धन्यवाद, लोडिंग घटक दिखाई देता है लेकिन हमेशा के लिए चल रहा रहता है: डी –

+0

'loading.present(); \t \t \t/* कुछ चीज़ें */ \t \t \t loading.onDidDismiss (() => {loading.dismiss();}); ' –

+0

मैं इस कोशिश की, लेकिन जैसा कि मैंने कहा, स्पिन हमेशा के लिए बदल रहता –

1

मैं डाल "loading.dismiss();" {} सदस्यता ले और यह अच्छी तरह से काम करता है :)

    this.http.get(url) 
         .subscribe(data =>{ 
          this.items=JSON.parse(data['_body']).results; 
          loading.dismiss(); 
         }, 
0

आप आयनिक ionViewLoaded उपयोग कर सकते हैं में लोड हो रहा है नियंत्रक पॉप अप करने के() और फिर इसे खारिज करें जब दृश्य लोड किया जाता है और अपने subscribtion से सामग्री लाई गई।

ionViewLoaded() { 
    let lr = this.loading.create({ 
    content: 'Your Display Message...', 
    }); 

    lr.present().then(() => { 
    this.Yourservice.Yourfunction() 
     .subscribe(res => { 
     this.yourresult = res; 
     }); 
    lr.dismiss(); 
    }); 
} 

आप लोडर को खारिज करने से पहले सदस्यता सुनिश्चित करने के लिए इस तरह अपना कोड भी बना सकते हैं।

ionViewLoaded() { 
     let lr = this.loading.create({ 
     content: 'Your Display Message...', 
     }); 

     lr.present().then(() => { 
     this.Yourservice.Yourfunction() 
      .subscribe(
      data => this.yourresult = data, 
      error => console.log(error), 
     ()=> lr.dismiss() 
     ); 

     }); 
    } 
संबंधित मुद्दे