【问题标题】:angular routing on ios9 $rootScope:infdig errorios9 $rootScope 上的角度路由:infdig 错误
【发布时间】:2015-10-30 18:32:17
【问题描述】:

在 ios8 中工作的 Angular 应用程序中的路由在 ios9 中产生 [$rootScope:infdig] 错误。 ngRouteui.router 我都试过了,但结果是一样的。

Error: [$rootScope:infdig] http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%5B%5D

有什么解决办法吗?

【问题讨论】:

标签: angularjs webview ios9


【解决方案1】:

即使这被标记为此问题的重复。这是解决此问题的最佳方法。

ionic app iOS 9 problems [$rootScope:infdig] 10 $digest() iterations reached

这篇文章中选择的答案会将您引导至此插件,该插件使用 Angular 修补所有 iOS9 问题。 https://gist.github.com/IgorMinar/863acd413e3925bf282c

此补丁适用于Angular 1.2.0 – 1.4.5,并且所有较新版本的 Angular 都将嵌入此修复。

【讨论】:

    【解决方案2】:

    这个答案来自Clever Coder on angular issue 12241,基于 Angular v1.4.3

    diff --git a/src/ng/browser.js b/src/ng/browser.js
    index 928de95..3b9957e 100644
    --- a/src/ng/browser.js
    +++ b/src/ng/browser.js
    @@ -87,7 +87,9 @@ function Browser(window, document, $log, $sniffer) {
       var cachedState, lastHistoryState,
           lastBrowserUrl = location.href,
           baseElement = document.find('base'),
    -      reloadLocation = null;
    +      reloadLocation = null,
    +      pendingHref = null,
    +      pendingHrefTimer = null;
    
       cacheState();
       lastHistoryState = cachedState;
    @@ -124,6 +126,18 @@ function Browser(window, document, $log, $sniffer) {
         if (location !== window.location) location = window.location;
         if (history !== window.history) history = window.history;
    
    +    // Schedule cleaning up pendingHref on the next run loop for setting URL. This is to handle
    +    // the case where the browser doesn't update the location.* properties immediately
    +    if (!pendingHrefTimer && pendingHref && url) {
    +      pendingHrefTimer = setTimeout(function () {
    +        if (location.href == pendingHref) {
    +          console.log('Actual href updated... setting pendingHref to null from setTimeout');
    +          pendingHref = null;
    +        }
    +        pendingHrefTimer = null;
    +      }, 0);
    +    }
    +
         // setter
         if (url) {
           var sameState = lastHistoryState === state;
    @@ -147,6 +161,7 @@ function Browser(window, document, $log, $sniffer) {
             // Do the assignment again so that those two variables are referentially identical.
             lastHistoryState = cachedState;
           } else {
    +        pendingHref = url;
             if (!sameBase || reloadLocation) {
               reloadLocation = url;
             }
    @@ -161,10 +176,22 @@ function Browser(window, document, $log, $sniffer) {
           return self;
         // getter
         } else {
    +      var href = location.href.replace(/%27/g, "'");
    +      if (pendingHref) {
    +        //console.log('.. using pendingHref for url() return value');
    +        href = pendingHref;
    +      }
    +
    +      if (location.href == pendingHref) {
    +        console.log('Actual href updated... setting pendingHref to null in getter');
    +        pendingHref = null;
    +      }
    +
    +      //var href = location.href.replace(/%27/g,"'");
           // - reloadLocation is needed as browsers don't allow to read out
           //   the new location.href if a reload happened.
           // - the replacement is a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=407172
    -      return reloadLocation || location.href.replace(/%27/g,"'");
    +      return reloadLocation || href;
         }
       };
    

    显然解决了这个问题,但在其他版本的 Angular 中没有。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多