Ionic2 trying too refresh content/list

Hey all :slight_smile: , I have a small issue of when I’m trying to update data I get the following error:

ORIGINAL EXCEPTION: Attempt to use a destroyed view: detectChanges

Which is weird…I feel I’m missing something ?

It happens when refreshProject Function is called

  ionViewDidEnter() {
      this.app.setTitle('Project');
      this.updateProjects();
  }

  updateProjects() {
   this.projects = [];
    // Close any open sliding items when the schedule updates
    // this.scheduleList && this.scheduleList.closeSlidingItems();
        this.loading.present();
        this.user.getProjects().then(data => {
            this.loading.dismiss();
            if (data['status'] === 200) {
                this.loading.dismiss();
                this.projects = data['data'];
            } else {
                this.loading.dismiss();
            }
        });
  }

refreshProject(){
  this.projects = [];
    this.updateProjects();
}
onViewDidEnter() {
      this.projects = [];
      this.app.setTitle('Project');
      this.updateProjects();
  }

  updateProjects() {
        this.loading.present();
        this.user.getProjects().then(data => {
            this.loading.dismiss();
            if (data['status'] === 200) {
                this.projects = data['data'];
            }
        });
  }

refreshProject(){
    this.updateProjects();
}

Try this.

@jagansai Thanks. But it did not help , but thanks for cleaning up my code. more information about the error…

zone.js:260 Uncaught EXCEPTION: Error in build/pages/projects/projects.html:7:20
ORIGINAL EXCEPTION: Attempt to use a destroyed view: detectChanges
ORIGINAL STACKTRACE:
Error: Attempt to use a destroyed view: detectChanges
    at ViewDestroyedException.BaseException [as constructor] (http://localhost:8100/build/js/app.bundle.js:2304:23)
    at new ViewDestroyedException (http://localhost:8100/build/js/app.bundle.js:31689:16)
    at DebugAppView.AppView.throwDestroyedError (http://localhost:8100/build/js/app.bundle.js:32237:72)
    at DebugAppView.AppView.detectChanges (http://localhost:8100/build/js/app.bundle.js:32184:18)
    at DebugAppView.detectChanges (http://localhost:8100/build/js/app.bundle.js:32291:44)
    at DebugAppView.AppView.detectViewChildrenChanges (http://localhost:8100/build/js/app.bundle.js:32212:19)
    at DebugAppView._View_LoadingCmp_Host0.detectChangesInternal (LoadingCmp.template.js:32:8)
    at DebugAppView.AppView.detectChanges (http://localhost:8100/build/js/app.bundle.js:32186:14)
    at DebugAppView.detectChanges (http://localhost:8100/build/js/app.bundle.js:32291:44)
    at ViewRef_.detectChanges (http://localhost:8100/build/js/app.bundle.js:32643:65)
ERROR CONTEXT:
[object Object]

How are you calling refreshProject() ?

Just using a normal button click

<ion-buttons end>
    <button (click)="refreshProject()">
    <ion-icon name="refresh"></ion-icon>
</button>
</ion-buttons>

@jagansai Finally Got it too work :relaxed: .
It had to do with my loading. As soon as I created a new loadingController everything worked.

refreshProject(){
        this.projects = [];
        let refresh = this.loadingController.create({
        content: 'Refreshing...'
        });
        refresh.present();
        this.user.getProjects().then(data => {
            if (data['status'] === 200) {
                console.log(data);
                 this.projects = data['data'];
            }
       refresh.dismiss();
        });
}