# EXCEPTION: Attempt to use a destroyed view: detectChanges

**URL:** <https://forum.ionicframework.com/t/exception-attempt-to-use-a-destroyed-view-detectchanges/61507>\
**Category:** ionic-v3\
**Created:** [August 24, 2016, 9:42pm UTC](https://forum.ionicframework.com/t/exception-attempt-to-use-a-destroyed-view-detectchanges/61507 "2016-08-24T21:42:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonwaters](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jasonwaters/32/96926_2.png) [@jasonwaters](https://forum.ionicframework.com/u/jasonwaters)\
**Post date:** [August 24, 2016, 9:42pm UTC](https://forum.ionicframework.com/t/exception-attempt-to-use-a-destroyed-view-detectchanges/61507/1 "2016-08-24T21:42:32Z")

</div>

I am noticing a strange error in my app. It’s related to dismissing modals. I use `this.nav.setRoot(page)` to separate different sections of my app. One way to guarantee that this error happens is this:

1. Load the app already logged in so it loads HomePage via setRoot.
2. the user logs out, which causes a `setRoot` for WelcomePage.
3. user clicks a button to open a modal on the welcome page. ( `let modal = this.modalController.create(...); modal.present()` )
4. within the modal, the user clicks a button to close the modal. ( `this.viewCtrl.dismiss();` )
5. EXCEPTION: Attempt to use a destroyed view: detectChanges

Anybody else seeing this exception in their app? The steps above are the only way I can dupe it every time, but I know it happens in other places too.

---

<div class="post-metadata">

**Author:** ![vaibsVB](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vaibsvb/32/102515_2.png) [@vaibsVB](https://forum.ionicframework.com/u/vaibsVB)\
**Post date:** [August 30, 2016, 8:03am UTC](https://forum.ionicframework.com/t/exception-attempt-to-use-a-destroyed-view-detectchanges/61507/2 "2016-08-30T08:03:14Z")

</div>

@jasonwaters Yess. You are right.

I’m also facing the same issue with `Loading` component.

If I’ve more than one `Loading Component` in my page.

The first one `Loading` is working properly but after that remaining `Loading` not working.  
They show `Attempt to use a destroyed view: detectChanges` error in console.

Have anyone find solution for this.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![rivera23](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@rivera23](https://forum.ionicframework.com/u/rivera23)\
**Post date:** [September 21, 2016, 7:30pm UTC](https://forum.ionicframework.com/t/exception-attempt-to-use-a-destroyed-view-detectchanges/61507/3 "2016-09-21T19:30:14Z")

</div>

Hi.  
I had the same (detectChanges error)  
Solves using two loading

```auto
getAll() {
    let loading = this.loadingCtrl.create({
      content: 'Please wait...'
    });

    loading.present();

    this.dataProvider.getData().subscribe(
        data => {
          this.listData = data; 
          loading.dismiss()
        },  
        error => this.errorMessage = <any>error
    );
}

presentModal() {
    let loading = this.loadingCtrl.create({
      content: 'Please wait...'
    });

    let modal = this.modalCtrl.create(ModalPage);
    
    modal.present();  
    
    modal.onDidDismiss(data => {

        loading.present();

        this.dataProvider.addData(data).subscribe(
            data => {
                this.listData.unshift(data);
                loading.dismiss()
            },
            error => this.errorMessage = <any>error
        );
    });
}

```
