离子刷新器会在页面加载时自动触发吗?

时间:2019-04-24 04:35:21

标签: firebase ionic-framework

离子刷新器似乎可以刷新页面,而无需手动调用doRefresh。我希望刷新器仅在“拉下”动作完成后才执行。

好像doRefresh会自动在“ ionviewdidload”功能上执行。

<ion-refresher (ionRefresh)="doRefresh($event);">
  <ion-refresher-content 
       pullingText="Pull to refresh" pullingIcon="arrow-dropdown" 
       refreshingSpinner="circles"
       refreshingText="..fetching">
   </ion-refresher-content> 
</ion-refresher>

home.ts

    doRefresh(refresher) {

    console.log('the current tab that is set = ' + this.tabSelId);



    console.log('testing');
    this.user = JSON.parse(window.localStorage.getItem('user'));
    let self_ = this;
    let devicePos = null;


    let devicelat = null;
    let devicelong = null;

    Geolocation.getCurrentPosition().then((position) => {


        // self_.loadingData(devicePos);
        devicelat = position.coords.latitude;
        devicelong = position.coords.longitude;

        self_.get_all_posts(devicelat, devicelong, self_.tabSelId);

        refresher.complete();



    }, (err) => {
        console.log('failed to get lat and long :' + err);

            self_.get_all_posts(devicelat, devicelong, self_.tabSelId);



        // self_.filter_posts_by_type(self_.tabSelId);

        // loading.dismiss();
        // refresher.complete();


    });



}

在ionviewdidload函数(home.ts)上:

    ionViewDidLoad(){

    this.user = JSON.parse(window.localStorage.getItem('user'));
    let self_ = this;
    let devicePos = null;

        console.log('the current tab that is set = '+this.tabSelId);

    let devicelat = null;
    let devicelong = null;

    Geolocation.getCurrentPosition().then((position) => {

        devicelat = position.coords.latitude;
        devicelong = position.coords.longitude;

        console.log('%c executing when position is got successfully ', 'background: #222; color: #bada55');


        self_.get_all_posts(devicelat, devicelong, self_.tabSelId);


        console.log('executing when position is got successfully');


    }, (err) => {
        console.log('failed to get lat and long :' + err);

            devicelat = 28.318237;
            devicelong = 111.168137;

            self_.get_all_posts(devicelat, devicelong, self_.tabSelId);



    });

使用

时的默认行为吗?
  

“离子刷新器”

我希望仅在“拉下”动作完成时才触发刷新器。 不知道为什么在加载应用程序时(仅第一次)执行doRefresh()函数

1 个答案:

答案 0 :(得分:2)

在您的HTML中使用like ..

<ion-refresher slot="fixed" (ionRefresh)="doRefresh($event)">
    <ion-refresher-content pullingIcon="arrow-dropdown" pullingText="Pull to refresh" refreshingSpinner="circles"
      refreshingText="Refreshing...">
    </ion-refresher-content>
  </ion-refresher>

在.ts中使用...

 doRefresh(event) {
    this.userPost();
    setTimeout(() => {
      event.target.complete();
    }, 2000);
  }