Ionic - View Leave Events Never Called

后端 未结 4 586
旧巷少年郎
旧巷少年郎 2021-01-19 00:41

After updating an existing Ionic project from 1.13-beta to 1.14-beta I\'ve experienced some behaviour I can\'t explain. When changing from one viewstate to another, the old

4条回答
  •  后悔当初
    2021-01-19 00:57

    I had this problem the other day. I was listening for the event on my child controllers. When I moved the listener to the parent, it worked. I wasn't quite sure why, but now I think I know why. It's because of the way Ionic caches the views. Specifically this line from the docs:

    If a view leaves but is cached, then this event will not fire again on a subsequent viewing.

    It's likely that your views were cached before you added the listener and the leave event never fired. But since your parent is... well... the parent, its leave event is triggered any time you leave any of its children. I haven't officially tested this, it's just a hunch. To test, try telling ionic to not cache the view by adding cache-view="false" to your ion-view declaration.

    See docs here.

提交回复
热议问题