Angularjs IE 11+;安格拉斯。locationChangeStart和preventDefault()上的错误

Angularjs IE 11+;安格拉斯。locationChangeStart和preventDefault()上的错误,angularjs,internet-explorer-11,Angularjs,Internet Explorer 11,我尝试将更改路由的提示写入控制器 代码: 视图: JS: console.clear(); var-app=angular.module(“app”,[“ngRoute”]); app.controller(“Test1”,函数($rootScope){ var$offFunction=$rootScope.$on(“$locationChangeStart”,函数(e){ 如果(确认(“您确定”)返回$offFunction(); 返回e.preventDefault(); }); })

我尝试将更改路由的提示写入控制器

代码:



视图:
JS:

console.clear();
var-app=angular.module(“app”,[“ngRoute”]);
app.controller(“Test1”,函数($rootScope){
var$offFunction=$rootScope.$on(“$locationChangeStart”,函数(e){
如果(确认(“您确定”)返回$offFunction();
返回e.preventDefault();
});
})
app.config(函数($routeProvider){
var tmpl1=“尝试更改路线时显示消息。错误:\n1.单击“测试2”。在提示下单击“取消”
+“\n2.再次单击以测试2”
+“\n3.没有提示消息”
+“\n仅在IE上”;
$routeProvider
.when(“/”,{模板:tmpl1,控制器:“Test1”})
.when(“/Test2”,{template:“Test2”})
})
问题:

在IE11、IE10中,如果单击Test2,请选中“取消”,然后再次单击Test2-locationChangeStart不再调用。如何修复它

IE9一切正常


该问题是由于您的
a
标签放错位置造成的。它们应该放在ng应用程序中,作为
a
不仅仅是标签,而是角度指示。见更正

<a href="#/">Test</a>
<a href="#/Test2">Test2</a>
<hr/>

<div ng-app='app'>
    <pre>View:
        <ng-view></ng-view>
    </pre>

</div>
console.clear();

var app = angular.module("app",["ngRoute"]);

app.controller("Test1", function($rootScope){
    var $offFunction = $rootScope.$on("$locationChangeStart", function(e) {
      if (confirm("Are you sure")) return $offFunction();
      return e.preventDefault();
    });

})

app.config(function($routeProvider){
    var tmpl1 = "Show message when you try change route. Bug: \n1. Click to 'Test2'. On prompt click cancel."
    +"\n2. Click to Test2 again"
    +"\n3. There is no prompt message"
    +"\n <i>Only on IE</i>";
    $routeProvider
    .when("/", {template:tmpl1, controller: "Test1"})
    .when("/Test2", {template:"Test 2"})
})