angular routing on ios9 $rootScope:infdig error

前端 未结 2 558
你的背包
你的背包 2020-12-31 20:25

Routing in angular app that worked in ios8, produces a [$rootScope:infdig] error in ios9. I have tried both ngRoute and ui.router but the result is

相关标签:
2条回答
  • 2020-12-31 20:34

    This answer from Clever Coder on angular issue 12241 based on 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;
         }
       };
    

    Apparently resolves the issue, but not in other versions of Angular.

    0 讨论(0)
  • 2020-12-31 20:43

    Even though this is marked as a duplicate of this question. This is the best way to resolve this issue.

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

    The selected answer in this post directs you over to this plugin which patches all the iOS9 issues with angular. https://gist.github.com/IgorMinar/863acd413e3925bf282c

    This Patch works for Angular 1.2.0 – 1.4.5 and all newer versions of angular will have this fix embedded.

    0 讨论(0)
提交回复
热议问题