简体   繁体   English

在AngularJS中使用不带哈希的ngView指令

[英]Using ngView directive without hash in angularjs

AngularJS Part: AngularJS部分:

myApp.config(['$routeProvider','$locationProvider',function($routeProvider,$locationProvider) {
    $routeProvider.
    when('/main', {templateUrl: 'sub/main.tpl', controller: MainCtrl}).
    when('/users', {templateUrl: 'sub/users.tpl', controller: UserCtrl}).
    otherwise({redirectTo: '/main'});
}]);

and my index.html 和我的index.html

<a href="#/main">Main</a> | <a href="#/users">Display Users</a>
<div ng-view></div>

It works great but I am having problem with hashes. 它很好用,但是我在哈希上遇到了问题。

When I try to use an anchor ie: 当我尝试使用锚,即:

<a href="#test">test</a>

when I click on this anchor it is calling the main page. 当我单击该锚点时,它正在调用主页。

Is it possible to get rid of the hashes when we use ng-view? 当我们使用ng-view时,是否有可能消除哈希值?

Ah, because AngularJS reroutes your urls. 嗯,因为AngularJS会重新路由您的网址。 Try using ng-href, 尝试使用ng-href,

<a ng-href="#test">test</a>

Edit: You can try changing the id of the anchor to the angular url.. 编辑:您可以尝试将锚点的ID更改为角度网址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM