<bdo id='46w4w'></bdo><ul id='46w4w'></ul>
  • <legend id='46w4w'><style id='46w4w'><dir id='46w4w'><q id='46w4w'></q></dir></style></legend>

  • <small id='46w4w'></small><noframes id='46w4w'>

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

        使用 ui-router 和 ion-tabs 时模板不更新

        Template does not update when using ui-router and ion-tabs(使用 ui-router 和 ion-tabs 时模板不更新)
      1. <i id='a7WTZ'><tr id='a7WTZ'><dt id='a7WTZ'><q id='a7WTZ'><span id='a7WTZ'><b id='a7WTZ'><form id='a7WTZ'><ins id='a7WTZ'></ins><ul id='a7WTZ'></ul><sub id='a7WTZ'></sub></form><legend id='a7WTZ'></legend><bdo id='a7WTZ'><pre id='a7WTZ'><center id='a7WTZ'></center></pre></bdo></b><th id='a7WTZ'></th></span></q></dt></tr></i><div id='a7WTZ'><tfoot id='a7WTZ'></tfoot><dl id='a7WTZ'><fieldset id='a7WTZ'></fieldset></dl></div>
          <bdo id='a7WTZ'></bdo><ul id='a7WTZ'></ul>
            <tbody id='a7WTZ'></tbody>

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

            • <tfoot id='a7WTZ'></tfoot>
              1. <legend id='a7WTZ'><style id='a7WTZ'><dir id='a7WTZ'><q id='a7WTZ'></q></dir></style></legend>

                  本文介绍了使用 ui-router 和 ion-tabs 时模板不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  代码

                  http://codepen.io/hawkphil/pen/LEBNVB

                  我有两个来自侧面菜单的页面(link1link2).每页有 2 个标签:

                  I have two pages (link1 and link2) from the side menu. Each page has 2 tabs:

                  link1:tab 1.1tab 1.2

                  link2:tab 2.1tab 2.2

                  我正在为每个页面使用 ion-tabs 以包含 2 个选项卡.

                  I am using ion-tabs for each page to contain the 2 tabs.

                  这是一个非常简单的设计:我想点击 link1link2 去合适的路线.但由于某种原因,状态已正确更改(请参阅控制台),但实际的 html 模板没有更新.您能找出问题所在以及如何解决吗?

                  This is a very simple design: I want to click on the link1 or link2 to go to appropriate route. But for some reason, the state has changed correctly (see Console) but the actual html template did not get updated. Can you find out what's wrong and how to fix?

                  好像有缓存问题什么的.

                  There seems to be some caching problem or something.

                  HTML

                  <title>Tabs Example</title>
                  
                  <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
                  <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
                  

                  <ion-side-menus enable-menu-with-back-views="false">
                    <ion-side-menu-content>
                      <ion-nav-bar class="bar-positive">
                        <ion-nav-back-button>
                        </ion-nav-back-button>
                  
                        <ion-nav-buttons side="left">
                          <button class="button button-icon button-clear ion-navicon" menu-toggle="left">
                          </button>
                        </ion-nav-buttons>
                        <ion-nav-buttons side="right">
                          <button class="button button-icon button-clear ion-navicon" menu-toggle="right">
                          </button>
                        </ion-nav-buttons>
                      </ion-nav-bar>
                      <ion-nav-view name="menuContent"></ion-nav-view>
                    </ion-side-menu-content>
                  
                    <ion-side-menu side="left">
                      <ion-header-bar class="bar-balanced">
                        <h1 class="title">Left</h1>
                      </ion-header-bar>
                      <ion-content>
                        <ion-list>
                          <ion-item nav-clear menu-close ui-sref="link1">
                            Link 1
                          </ion-item>
                          <ion-item nav-clear menu-close ui-sref="link2">
                            Link 2
                          </ion-item>
                        </ion-list>
                      </ion-content>
                    </ion-side-menu>
                  
                    <ion-side-menu side="right">
                      <ion-header-bar class="bar-calm">
                        <h1 class="title">Right Menu</h1>
                      </ion-header-bar>
                      <ion-content>
                        <div class="list list-inset">
                          <label class="item item-input">
                            <i class="icon ion-search placeholder-icon"></i>
                            <input type="text" placeholder="Search">
                          </label>
                        </div>
                        <div class="list">
                          <a class="item item-avatar" href="#">
                            <img src="img/avatar1.jpg">
                            <h2>Venkman</h2>
                            <p>Back off, man. I'm a scientist.</p>
                          </a>
                        </div>
                      </ion-content>
                    </ion-side-menu>
                    </ion-side-menus>
                  </ion-side-menus>
                  
                  <script id="link1.html" type="text/ng-template">
                    <ion-tabs class="tabs-icon-top tabs-positive">
                  
                      <ion-tab title="Home" icon="ion-home">
                        <ion-view view-title="Home">
                          <ion-content has-header="true" has-tabs="true" padding="true">
                            <p>Test</p>
                            <p>Test Tab 1.1</p>
                          </ion-content>
                        </ion-view>          
                      </ion-tab>
                  
                      <ion-tab title="About" icon="ion-ios-information">
                        <ion-view view-title="Home">
                          <ion-content has-header="true" has-tabs="true" padding="true">
                            <p>Test</p>
                            <p>Test Tab 1.2</p>
                          </ion-content>
                        </ion-view> 
                      </ion-tab>
                  
                    </ion-tabs>
                  </script>
                  
                  <script id="link2.html" type="text/ng-template">
                    <ion-tabs class="tabs-icon-top tabs-positive">
                  
                      <ion-tab title="Home" icon="ion-home">
                        <ion-view view-title="Home">
                          <ion-content has-header="true" has-tabs="true" padding="true">
                            <p>Test</p>
                            <p>Test Tab 2.1</p>
                          </ion-content>
                        </ion-view>          
                      </ion-tab>
                  
                      <ion-tab title="About" icon="ion-ios-information">
                        <ion-view view-title="Home">
                          <ion-content has-header="true" has-tabs="true" padding="true">
                            <p>Test</p>
                            <p>Test Tab 2.2</p>
                          </ion-content>
                        </ion-view> 
                      </ion-tab>
                  
                    </ion-tabs>
                  </script>
                  

                  JS

                  angular.module('ionicApp', ['ionic'])
                  
                  .config(function($stateProvider, $urlRouterProvider) {
                  
                    $stateProvider
                      .state('link1', {
                        url: "/link1",
                        views: {
                          'menuContent': {
                            templateUrl: "link1.html"
                          }
                        }
                      })
                      .state('link2', {
                        url: "/link2",
                        views: {
                          'menuContent': {
                            templateUrl: "link2.html"
                          }
                        }
                      });
                  
                     $urlRouterProvider.otherwise("/link1");
                  
                  })
                  
                  .controller('AppCtrl', ['$scope', '$rootScope', '$state', '$stateParams', function($scope, $rootScope, $state, $stateParams) {
                  
                    $rootScope.$on('$stateChangeSuccess', function(evt, toState, toParams, fromState, fromParams) {
                      console.log(toState);
                    });
                  
                  }])
                  

                  推荐答案

                  您当前指的是最新版本 1.0.0-rc.0,从一种状态转换到另一个它没有加载视图.

                  You are currently referring to the latest release which is 1.0.0-rc.0 which has bug while transition from one state to another it is not loading the view.

                  进一步研究发现,在他们现在的版本之后,从版本 1.0.0-beta.11.0.0-beta.14 有 14 个 beta 版本1.0.0-rc.0 是候选版本.

                  Further research found that, they had 14 beta releases from version 1.0.0-beta.1 to 1.0.0-beta.14 after they are now on version 1.0.0-rc.0 which is release candidate.

                  nav-view1.0.0-beta.13 版本之前工作完美,但在 1.0.0-beta.14 之后停止工作>(这是最后一个测试版),

                  nav-view is working perfect till 1.0.0-beta.13 version but it stop working after 1.0.0-beta.14(which is last beta release),

                  我建议你将你的版本降级到 1.0.0-beta.13,我知道依赖 beta 版本并不是一件好事,但在 ionic 发布稳定版本之前你必须依赖它.

                  I would suggest you to degrade your version to 1.0.0-beta.13, I know depending on beta version is not good thing but still until ionic release stable version you have to rely on it.

                  工作 Codepen1.0.0-beta.13

                  更新:

                  您的问题是您的视图正在被缓存,因为默认情况下,您的 ionic 应用程序中启用了缓存.

                  Your problem is your view are getting cached because by default caching is enabled inside your ionic app.

                  直接来自 Ionic Doc(最新发布的文档 1.0.0-beta.14)

                  Straight from Ionic Doc (Latest Release doc 1.0.0-beta.14)

                  默认情况下,视图被缓存以提高性能.当一个视图是导航离开,它的元素留在 DOM 中,它的范围是与 $watch 周期断开连接.当导航到一个视图时已经缓存,然后重新连接其范围,并且现有的留在 DOM 中的元素成为活动视图.这也是允许保持先前视图的滚动位置.缓存视图的最大容量为 10.

                  By default, views are cached to improve performance. When a view is navigated away from, its element is left in the DOM, and its scope is disconnected from the $watch cycle. When navigating to a view that is already cached, its scope is then reconnected, and the existing element that was left in the DOM becomes the active view. This also allows for the scroll position of previous views to be maintained.Maximum capacity of caching view is 10.

                  因此,通过在 $stateProvider 状态函数上提及 cache: false 或通过执行 $ionicConfigProvider.views.maxCache(0) 全局禁用导航视图的缓存; 在 Angular 配置阶段内.

                  So by mentioning cache: false on $stateProvider states function or disabling cache of nav-view globally by doing $ionicConfigProvider.views.maxCache(0); inside angular config phase.

                  因此,在您的情况下,这正是问题所在,您的第一个视图正在获取缓存和再次显示它&再次

                  So in your case this is what exact problem, your 1st view is getting cache & showing it again & again

                  有3种方法可以解决这个问题

                  There are 3 ways to solve this issue

                  1.全局禁用缓存

                  通过将其设置为 0 来禁用所有缓存,然后在使用它之前添加 $ionicConfigProvider 依赖项.

                  Disable all caching by setting it to 0, before using it add $ionicConfigProvider dependency.

                  $ionicConfigProvider.views.maxCache(0);
                  

                  Codepen

                  <强>2.在状态提供程序中禁用缓存

                  $stateProvider
                  .state('link1', {
                    url: "/link1",
                    cache: false,
                    views: {
                      'menuContent': {
                        templateUrl: "link1.html"
                      }
                    }
                  })
                  .state('link2', {
                    url: "/link2",
                    cache: false,
                    views: {
                      'menuContent': {
                        templateUrl: "link2.html"
                      }
                    }
                  });
                  

                  Codepen

                  3.使用属性禁用缓存

                      <ion-tab title="Home" icon="ion-home">
                        <ion-view cache-view="false" view-title="Home">
                          <!-- Ion content here -->
                        </ion-view>          
                      </ion-tab>
                  
                      <ion-tab title="About" icon="ion-ios-information">
                        <ion-view cache-view="false" view-title="Home">
                          <!-- Ion content here -->
                        </ion-view> 
                      </ion-tab>
                  

                  Codepen

                  我相信更新后的方法非常适合实施.谢谢.

                  I believe the updated approach would be great to implement. Thanks.

                  同一问题的 Github 问题此处链接

                  Github issue for the same issue link here

                  这篇关于使用 ui-router 和 ion-tabs 时模板不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)

                  <tfoot id='OyQI2'></tfoot>
                  <legend id='OyQI2'><style id='OyQI2'><dir id='OyQI2'><q id='OyQI2'></q></dir></style></legend>

                    <bdo id='OyQI2'></bdo><ul id='OyQI2'></ul>
                        <tbody id='OyQI2'></tbody>
                    • <small id='OyQI2'></small><noframes id='OyQI2'>

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