0

我使用 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>

我不太了解角度,所以你能帮我解决这个错误吗?

谢谢。

4

1 回答 1

2

$locationAuth 应该是 ($location, Auth)。

我认为这也可能在最近的提交中得到修复,因此您可能只需更新您的生成器。

于 2015-12-16T21:46:58.693 回答