IE 中 window.location.assign(url) 的角度摘要错误

Pra*_*lee -1 javascript internet-explorer angularjs

我正在使用 Angular JS,每当我尝试使用 window.location.assign(url) 更改窗口位置 url 时,都会出现以下错误。这种情况只发生在 IE 中 这是我得到的错误:

10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["fn: function $locationWatch() {\n      var oldUrl = $browser.url();\n      var currentReplace = $location.$$replace;\n\n      if (!changeCounter || oldUrl != $location.absUrl()) {\n        changeCounter++;\n        $rootScope.$evalAsync(function() {\n          if ($rootScope.$broadcast('$locationChangeStart', $location.absUrl(), oldUrl).\n              defaultPrevented) {\n            $location.$$parse(oldUrl);\n          } else {\n            $browser.url($location.absUrl(), currentReplace);\n            afterLocationChange(oldUrl);\n          }\n        });\n      }\n      $location.$$replace = false;\n\n      return changeCounter;\n    }; newVal: 9; oldVal: 8","fn: function ngModelWatch() {\n    var value = ngModelGet($scope);\n\n    // if scop
Run Code Online (Sandbox Code Playgroud)

我的 JS 代码从中进行调用:

$scope.onRowClick = function(selected, row, $event) {       
        if(selected){
            window.location.assign("/lora/#/origination/" + row.loanRequestNo); 
        }
    };
Run Code Online (Sandbox Code Playgroud)

我的路由器js。

var app = angular.module('loraApp', []);

app.config([ '$routeProvider', function($routeProvider) {
    $routeProvider.when('/dashboard', {
        templateUrl : 'app/html/dashboard.html'
    }).when('/origination', {
        templateUrl : 'app/html/origination/origination.html' , controller: 'OriginationCtrl'
    }).otherwise({
        redirectTo : '/dashboard'
    });
} ]);
Run Code Online (Sandbox Code Playgroud)

我正在尝试从 /dashboard 导航到 /origination。但是当我尝试从 /origin 导航到 /origin 时也会发生这种情况。基本上每当我的代码遇到 window.location.url 时就会发生这种情况

Bro*_*cco 5

您需要注入$location控制器,然后使用设置路径$location

$location.url('/organization/' + row.loanRequestNo);
Run Code Online (Sandbox Code Playgroud)

$location 文档

根据您定义的路由进行编辑,您不会收到参数 row.loanRequestNo。您需要将该路线更新为:

/organization/:loadRequestNo
Run Code Online (Sandbox Code Playgroud)

并通过$routeParams在目标控制器上捕获它

编辑 工作小提琴