使用ngTouch重定向与ngRoute不工作与href和ng-click属性

时间:2022-06-14 21:48:26

I navigate through the app with ngRoute. I use links like:

我用ngRoute浏览这个应用。我使用的链接:

<a href="#/page2" ng-click="showOffCanvas = false">Link</a>

Since I use ngTouch the navigation doesn't work on touch devices. I tried it with an android phone and with chrome's device emulator. On the desktop everything works fine.

由于我使用ngTouch,所以导航在触控设备上不能工作。我用android手机和chrome的设备模拟器进行了测试。在桌面,一切都运行良好。

When I remove ngTouch this problem disappears. It also disappears when I remove the ng-click attribute.

当我移除ngTouch时,这个问题就消失了。当我删除ng-click属性时,它也会消失。

Linking to:

链接:

<a href="www.google.com" ng-click="showOffCanvas = false">google</a>

is working on every device. It seems that only the routing with ngRoute stops to work, when I include ngTouch.

每个设备都在工作。似乎只有带有ngRoute的路由停止工作,当我包含ngTouch时。

What would be the solution?

解决方案是什么?

1 个解决方案

#1


2  

It is an old bug, that wasn't fixed before this time. Href and ng-click doesn`t work together.

这是一个旧的bug,在此之前没有修复。Href和ng-click不能一起工作。

A workaround could be to use an empty href and put the navigation logic into ng-click using $location.

一个解决方案是使用一个空的href并使用$location将导航逻辑放入ng-click中。

Proof: https://github.com/angular/angular.js/issues/5307#issuecomment-30024683

证明:https://github.com/angular/angular.js/issues/5307 # issuecomment - 30024683

In HTML:

在HTML中:

<a href="" ng-click="showOffCanvas = false; goTo('#/page2')">Link</a>

In controller:

控制器:

$scope.goTo = function(refer){
    $location.path(refer)
};

#1


2  

It is an old bug, that wasn't fixed before this time. Href and ng-click doesn`t work together.

这是一个旧的bug,在此之前没有修复。Href和ng-click不能一起工作。

A workaround could be to use an empty href and put the navigation logic into ng-click using $location.

一个解决方案是使用一个空的href并使用$location将导航逻辑放入ng-click中。

Proof: https://github.com/angular/angular.js/issues/5307#issuecomment-30024683

证明:https://github.com/angular/angular.js/issues/5307 # issuecomment - 30024683

In HTML:

在HTML中:

<a href="" ng-click="showOffCanvas = false; goTo('#/page2')">Link</a>

In controller:

控制器:

$scope.goTo = function(refer){
    $location.path(refer)
};