Function on tab pages is loaded twice

I have a function in my work page that is one of the tabs. I wrote a function to load after the page requests data from the API.

Note. Apart from tab pages, open push pages work fine.

This worked fine on Ionic 3.0.1, however, once I switched to Ionic 3.1.0 when I went to the page, the function was loaded twice.

Here is my work.ts code

    ionViewWillEnter() {
        if(this.auth.authUser()) {
        this.isLogin = true;
        this.userData = this.auth.getUserInfo();
        } else {
        this.isLogin = false;
        }

        if(this.isLogin) {
        this.getClientList(true);
        } else {
        this.clientData = [];
        }
    }

    ...

    private getClientList(resetPage) {
        console.log('loaded getClientList');
        this.isEmpty = false;
        this.userData = this.auth.getUserInfo();
        if(resetPage) {
            this.content.scrollToTop(0);
            this.clientPage = 1;
        }
        let pageSkip = (this.clientPage-1)*this.clientPerPage;
        let postData = 'take=' + this.clientPerPage;
        postData += '&skip=' + pageSkip;
        postData += '&uid=' + this.userData.userId;
        if (this.category != '0') {
            postData += '&category=' + this.category;
        }
        if (this.gradeId) {
            postData += '&grade=' + this.gradeId;
        }

        let params = {
                link: 'app/client/my_client_list',
                data: postData,
        }
        this.showLoading('loading...');
        this.api.httpApi(params).subscribe(data => {
            this.loading.dismiss();
        if (data.status_code == 1) {
            this.clientData = [];
            if(data.data.length > 0) {
                this.clientData=data.data;
                // this.productState = 'in';
                if(this.clientPage < 1) {
                this.clientPage++;
                }

                if(data.data.length < this.clientPerPage) {
                this.isEnd = true;
                } else {
                this.isEnd = false;
                }
            } else {
                this.isEmpty = true;
                this.isEnd = false;
            }

        } else if (data.status_code == 500) {
            this.navCtrl.push('LoginPage');
        } else if (data.status_code == 0) {
            this.isEmpty = true;
            this.isEnd = false;
        } else {
            this.showError('network problem');
        }
        },
        error => {
        this.loading.dismiss();
        this.pushLogin();
        // this.showError(error);
        });
    }

      

console log outputs

Hello AuthService Provider
work.ts:173  loaded getClientList
work.ts:173  loaded getClientList

      

ionic information

Cordova CLI: 6.5.0
Ionic Framework Version: 3.1.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.3.4
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.10.2
Xcode version: Not installed

      

[EDIT]

There is work around which the API request function is included inside the constructor, then the function will only run once. But this does not solve the problem if you want to use IonViewWillEnter.

+3


source to share


1 answer


Obviously upgrading to Ionic 3.1.1 will fix this problem. If anyone else has this problem and you are still on Ionic version 3.1.0, just resolve the issue to version 3.1.1+.



0


source







All Articles