ui-router / quickstart-ng2

DEPRECATED -- See https://github.com/ui-router/quickstart-angular
https://github.com/ui-router/quickstart-angular
MIT License
64 stars 20 forks source link

What is this error(Uncaught (in promise):, EXCEPTION: No provider for UISref!)? #10

Closed kolkov closed 8 years ago

kolkov commented 8 years ago

Hi! I try to use this template for my own project, and I get this error:

<nav class="navbar navbar-fixed-top navbar-dark bg-inverse">
  <div class="container">
    <button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#navbar-header" aria-controls="navbar-header" (init)="isCollapsed = true" (click)="isCollapsed = !isCollapsed">
      &#9776;
    </button>
    <div class="collapse navbar-toggleable-xs" id="navbar-header" [ngbCollapse]="!isCollapsed && 'in'">
      <a class="navbar-brand" href="#">inFrame</a>
      <ul class="nav navbar-nav">
        <li uiSrefActive="active" class="nav-item">
          <a (click)='isCollapsed = true' class="nav-link" href uiSref="app.public.home">Главная <span class="sr-only">(current)</span></a>
        </li>
        <li uiSrefActive="active" class="nav-item">
          <a (click)='isCollapsed = true' class="nav-link" href uiSref="app.public.about">О нас</a>
        </li>
        <li uiSrefActive="active" class="nav-item">
          <a (click)='isCollapsed = true' class="nav-link" href uiSref="app.public.user.signup">Регистрация</a>
        </li>
        <li uiSrefActive="active" class="nav-item">
          <a (click)='isCollapsed = true' class="nav-item nav-link" href>Вход</a>
        </li>
      </ul>
      <form class="form-inline pull-xs-right">
        <input class="form-control" type="text" placeholder="Искать...">
        <button class="btn btn-outline-success" type="submit">Поиск</button>
      </form>
    </div><!-- /.navbar-header -->
  </div><!-- /.container -->
</nav><!-- /.navbar -->

What this?

image

christopherthielen commented 8 years ago

This is a bug in ui-router-ng2. The UISrefActive is only working if the UISref is on the same element.

The bug is from how we access the UISref, by injecting it into the constructor here: https://github.com/angular-ui/ui-router/blob/master/src/ng2/directives/uiSrefStatus.ts#L58

We should probably be using the ContentChild feature to find the child UISref(s): https://angular.io/docs/ts/latest/api/core/index/ContentChild-var.html

kolkov commented 8 years ago

Thanks!

kolkov commented 8 years ago

This fixed in pre 1.0.0-beta.2! Thanks!