【问题标题】:IE 11 + AngularJS. Bug on locationChangeStart and preventDefault()IE 11 + AngularJS。 locationChangeStart 和 preventDefault() 上的错误
【发布时间】:2014-04-26 00:05:52
【问题描述】:

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

代码:

<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,请选中“取消”并再次单击到 Test2 - locationChangeStart 不会再次调用。如何解决?

IE9 一切正常

JSFiddle

【问题讨论】:

    标签: angularjs internet-explorer-11


    【解决方案1】:

    问题是由于您的a 标记放错了位置造成的。它们应该放在 ng-app 中,因为 a 不仅是标签,还有角度指令。请参阅已更正的fiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-03
      • 2018-11-08
      • 2014-02-26
      • 2016-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多