我使用Generator Angular Fullstack v3.0.2生成了一个项目。我打开服务器,一切运作良好。但在客户端我遇到问题,我在控制台错误中收到错误:
[$ injector:unpr]未知提供者:$ locationAuthProvider< - $ locationAuth< - NavbarController
控制器
class NavbarController {
//start-non-standard
menu = [{
'title': 'Home',
'link': '/'
}];
isCollapsed = true;
//end-non-standard
constructor($locationAuth) {
this.$location = $location;
this.isLoggedIn = Auth.isLoggedIn;
this.isAdmin = Auth.isAdmin;
this.getCurrentUser = Auth.getCurrentUser;
}
isActive(route) {
return route === this.$location.path();
}
}
angular.module('rideSharingApp')
.controller('NavbarController', NavbarController);
HTML
<div class="navbar navbar-default navbar-static-top" ng-controller="NavbarController">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" type="button" ng-click="nav.isCollapsed = !nav.isCollapsed">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="/" class="navbar-brand">ride-sharing</a>
</div>
<div collapse="nav.isCollapsed" class="navbar-collapse collapse" id="navbar-main">
<ul class="nav navbar-nav">
<li ng-repeat="item in nav.menu" ng-class="{active: nav.isActive(item.link)}">
<a ng-href="{{item.link}}">{{item.title}}</a>
</li>
<li ng-show="nav.isAdmin()" ng-class="{active: nav.isActive('/admin')}"><a href="/admin">Admin</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li ng-hide="nav.isLoggedIn()" ng-class="{active: nav.isActive('/signup')}"><a href="/signup">Sign up</a></li>
<li ng-hide="nav.isLoggedIn()" ng-class="{active: nav.isActive('/login')}"><a href="/login">Login</a></li>
<li ng-show="nav.isLoggedIn()"><p class="navbar-text">Hello {{ nav.getCurrentUser().name }}</p> </li>
<li ng-show="nav.isLoggedIn()" ng-class="{active: nav.isActive('/settings')}"><a href="/settings"><span class="glyphicon glyphicon-cog"></span></a></li>
<li ng-show="nav.isLoggedIn()"><a href="/logout">Logout</a></li>
</ul>
</div>
</div>
</div>
我不太了解角度,所以你能帮我解决这个错误吗?
感谢。
答案 0 :(得分:2)
$ locationAuth应为($ location,Auth)。
我认为这也可以在最近的提交中修复,以便您可以只更新您的生成器。