2017-05-08 12 views
0

我用活动指示灯在我的网页,但它不是躲在当我任何承诺,将其设置为false,但是当我设置为false以外的承诺是隐藏为什么Activity Indicator没有隐藏在nativescript中?

//My ts file 
public loadLanguages() { 
    this.isLoading= true; //where i am setting value true for activity indicator 
    for (var i = 0; i < 1; i++) { 
     this.ArrayLangauge.push("Select Langauge"); 
    } 
    this.registerService.language() 
     .then(a => { 
      if (a) { 
       for (var i = 0; i < a[0].languages.length; i++) { 

       } 
      } this.isLoading=false; ////where i am setting value false for activity indicator 
     }); 
} 


//my Html 
    <AbsoluteLayout height="100%" width="100%"> 
    <ActivityIndicator class="indicator" [busy]="isLoading" [visibility]=" isLoading ? 'visible' : 'collapse'" row="1" horizontalAlignment="center" verticalAlignment="center"></ActivityIndicator>  
</AbsoluteLayout> 
+0

shouldnt'this.isLoading = false'在'.then()'语句中? – mast3rd3mon

+0

是this.isLoading = false应该在.then()语句bcz里面,我从webservices –

+0

接收到可能有助于移动它的数据后将它设置为false,然后 – mast3rd3mon

回答

0

使用HTTP服务,并返回可观察:

import { Injectable } from '@angular/core'; 
import { Http } from '@angular/http'; 
import { Observable } from 'rxjs/Observable'; 
import "rxjs/Rx"; 
import { RequestOptions, Headers } from '@angular/http'; 

@Injectable() 
export class RegistrationService { 

    constructor(private http:Http, private apiCalls:ApiCalls) { 
    } 

    language():Observable<any> { 
     var myurl = this.apiCalls.BASE_URL + "languages"; 
     return this.http.get(`${myurl}`) 
      .map(this.extractData) 
      .catch(this.handleError); 
    } 

    private extractData(res:Response) { 
     let body = res.json(); 
     return body; 
    } 

    private handleError(error:Response | any) { 
     // In a real world app, we might use a remote logging infrastructure 
     console.log(JSON.stringify(error.json())); 
     return Observable.throw(error); 
    } 

} 

在你的组件,你可以做象下面这样:

this.isLoading = true; 
this.registrationService.language(this.user) 
      .subscribe((data) => { 
        console.log("success =>" + JSON.stringify(data)); 
//handle data as you like here 
        this.isLoading = false; 


       }, 
       (error:any) => { 
        console.log("error =>" + JSON.stringify(error)); 
        console.log(error.status); 

         this.isLoading = false; 


       } 
      ) 

在HTML模板:

<ActivityIndicator [busy]="isLoading" horizontalAlignment="center" verticalAlignment="center" [visibility]="isLoading? 'visible':'collapse'"></ActivityIndicator> 
+0

谢谢..但仍然活动指示符不隐藏 –

+0

添加一个标签,显示isLoading的值以进行调试,确保isLoading变为false

+0

你有你的控制台错误或成功? –

相关问题