<i id='AAGWy'><tr id='AAGWy'><dt id='AAGWy'><q id='AAGWy'><span id='AAGWy'><b id='AAGWy'><form id='AAGWy'><ins id='AAGWy'></ins><ul id='AAGWy'></ul><sub id='AAGWy'></sub></form><legend id='AAGWy'></legend><bdo id='AAGWy'><pre id='AAGWy'><center id='AAGWy'></center></pre></bdo></b><th id='AAGWy'></th></span></q></dt></tr></i><div id='AAGWy'><tfoot id='AAGWy'></tfoot><dl id='AAGWy'><fieldset id='AAGWy'></fieldset></dl></div>
      • <bdo id='AAGWy'></bdo><ul id='AAGWy'></ul>

      <tfoot id='AAGWy'></tfoot>
      1. <small id='AAGWy'></small><noframes id='AAGWy'>

        <legend id='AAGWy'><style id='AAGWy'><dir id='AAGWy'><q id='AAGWy'></q></dir></style></legend>

        在渲染“页面"之前获取数据异步

        时间:2023-09-08
        <i id='OOolB'><tr id='OOolB'><dt id='OOolB'><q id='OOolB'><span id='OOolB'><b id='OOolB'><form id='OOolB'><ins id='OOolB'></ins><ul id='OOolB'></ul><sub id='OOolB'></sub></form><legend id='OOolB'></legend><bdo id='OOolB'><pre id='OOolB'><center id='OOolB'></center></pre></bdo></b><th id='OOolB'></th></span></q></dt></tr></i><div id='OOolB'><tfoot id='OOolB'></tfoot><dl id='OOolB'><fieldset id='OOolB'></fieldset></dl></div>

            <legend id='OOolB'><style id='OOolB'><dir id='OOolB'><q id='OOolB'></q></dir></style></legend>
          • <small id='OOolB'></small><noframes id='OOolB'>

              <bdo id='OOolB'></bdo><ul id='OOolB'></ul>
                1. <tfoot id='OOolB'></tfoot>

                    <tbody id='OOolB'></tbody>

                2. 本文介绍了在渲染“页面"之前获取数据异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在渲染 Page 之前获取数据异步的正确方法是什么?

                  What is the correct way to get data async before a Page gets rendered?

                  Angular2 建议使用 @CanActivate 装饰器.可悲的是,这不适用于 Ionic2,至少不适用于我和 其他

                  Angular2 suggests the @CanActivate decorator as far as I understand it. Sadly this is not working with Ionic2, at least not for me and for others

                  显然 Ionic2 使用 @CanActivate 装饰器 见但它没有记录,我无法弄清楚它到底做了什么.

                  Apparently Ionic2 does something with the @CanActivate decorator, see But its not documented and i can't figure out what it does exactly.

                  尽管如此 这家伙指出应该使用 无论如何,由于离子缓存,离子视图状态.他的例子是这样的:

                  Nevertheless this guy points out one should use Ionics View States instead anyways, due to ionics caching. His example looks like this:

                    onPageWillEnter() { 
                        return this._service.getComments().then(data => this.comments = data);
                    }
                  

                  看起来他希望 Ionic 考虑返回的承诺,但是 快速浏览 离子源显示(至少我是这么认为的)返回值被忽略.因此,不能保证在页面呈现之前 会解决承诺.这是一个带有 onPage* 的 示例,以及它没有按需要/预期执行的原因.

                  Which looks like he is expecting Ionic to consider the returned promise, but a quick glance a Ionics sources reveals (at least I think so) that the returned value is ignored. Hence there is no guarantee that the promise gets resolved before the page gets rendered. Here is an example with onPage* and how it does not perform as needed/expected.

                  所以我迷路了,如何完成这个简单的任务?

                  So I'm lost, how does one achieve this simple task?

                  在第一个链接中,建议在导航到页面之前解析数据,这会增加被调用者知道页面需要哪些数据的负担.在我看来,这不是一个选择.

                  In the first link, it was suggested to resolve the data before navigating to the page, which burdens the knowledge which data is needed for the page on the callee. This is not an option in my opinion.

                  *添加反例

                  推荐答案

                  对于在使用 Ionic 2 时对 Stackoverflow 进行限制页面访问的任何人来说,Ionic 推荐的生命周期事件似乎是 ionViewCanEnter.

                  For anyone crawling Stackoverflow about restricting page access when using Ionic 2, it looks like Ionic's recommended lifecycle event to tap into is ionViewCanEnter.

                  来自文档:

                  ionViewCanEnter 在视图进入之前运行.这可以用作经过身份验证的视图中的一种守卫",您需要在视图进入之前检查权限.

                  ionViewCanEnter Runs before the view can enter. This can be used as a sort of "guard" in authenticated views where you need to check permissions before the view can enter.

                  http://ionicframework.com/docs/v2/api/navigation/NavController/

                  这篇关于在渲染“页面"之前获取数据异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:卡在按值/子键删除父推送键 下一篇:如何在 Ionic 2 中定位弹出框

                  相关文章

                  最新文章

                3. <legend id='zD2XM'><style id='zD2XM'><dir id='zD2XM'><q id='zD2XM'></q></dir></style></legend>

                    <tfoot id='zD2XM'></tfoot>

                    <small id='zD2XM'></small><noframes id='zD2XM'>

                        <bdo id='zD2XM'></bdo><ul id='zD2XM'></ul>
                      <i id='zD2XM'><tr id='zD2XM'><dt id='zD2XM'><q id='zD2XM'><span id='zD2XM'><b id='zD2XM'><form id='zD2XM'><ins id='zD2XM'></ins><ul id='zD2XM'></ul><sub id='zD2XM'></sub></form><legend id='zD2XM'></legend><bdo id='zD2XM'><pre id='zD2XM'><center id='zD2XM'></center></pre></bdo></b><th id='zD2XM'></th></span></q></dt></tr></i><div id='zD2XM'><tfoot id='zD2XM'></tfoot><dl id='zD2XM'><fieldset id='zD2XM'></fieldset></dl></div>