Angular <a href=""> links - odd behaviour

时间:2016-06-23 18:16:25

标签: angularjs ngroute

Folks I have real odd situation that doesn't seem to make sense to me at all. Here's my setup:

<html ng-app="mainApp">
    <head>blah</head>
<body>
    <header ng-controller="headerCntrl">
        <a href="#/profile">Profile</a>
    </header>
<blah>
<main ng-view></main>
<footer />
</body></html>

The header has it's own controller, then I use ngRoute to define various paths, including the profile:

.when('/profile', {
    templateUrl: 'views/profile.html',
    controller: 'profileController'
})

For some reason, clicking in the a href link in the header does nothing. No error, no activity. It does show the correct URL when you hover over the link, and, right-clicking and opening in new tab DOES work just fine.

Why does a normal left click not work? Bearing in mind that either:

  • Typing that route in directly into address bar &
  • Right click - open in new window

both work, what's stopping angular from loading that view into the div?

Any help much appreciated!

1 个答案:

答案 0 :(得分:0)

我认为问题是你没有指定base url。试试吧。