我尝试将改变路线上的提示写入控制器。
代码:
<a href="#/">Test</a>
<a href="#/Test2">Test2</a>
<hr/>
<div ng-app='app'>
<pre>View:
<ng-view></ng-view>
</pre>
</div>
JS:
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"})
})
问题:
在IE11,IE10中,如果单击Test2,请选中“取消”并再次单击“测试2” - 不再调用locationChangeStart。如何解决?
IE9一切正常