在注入Router Angularjs 2之前引导至少一个组件

Cle*_*ode 1 dependency-injection angular-services angular

我已经谷歌了很多这个问题,但没有找到任何相关的文章或stackoverflow问题虽然有很多问题具有相同的标题但在场景中有所不同.我无法在服务的构造函数上要求依赖项,这就是我收到此错误的原因.

Bootstrap at least one component before injecting Router. ; Zone: <root> ; Task: Promise.then ; Value: Error: Bootstrap at least one component before
Run Code Online (Sandbox Code Playgroud)

注意:如果我只是clear the constructor在其中定义的依赖关系,CustomerService class它就像一个魅力.

@Injectable()
export class CustomerService
constructor(private authService: AuthService, private siteService: SiteService) { } 
Run Code Online (Sandbox Code Playgroud)

AuthService和站点服务类及其依赖项加载没有问题.只是AuthService和SiteService类的一些sudo外观

@Injectable()
export class AuthService 
constructor(private http: Http, private storageService: StorageService, 
            private siteService: SiteService, private router: Router) {}


@Injectable()
export class SiteService {
constructor(private http: Http, private storageService: StorageService) {}
Run Code Online (Sandbox Code Playgroud)

还有App Module @ngModule装饰.

@NgModule({
  declarations: [
    AppComponent,
    AuthComponent,
    LoginComponent,
    HeaderComponent,
    SignupComponent,
    CompanyComponent,
    Step2Component
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    AngularAppRoutingModule
  ],
  providers: [ AuthGuard, AuthService, StorageService, StepsNavigatorGuard, SiteService, CustomerService],
  bootstrap: [AppComponent]
})
Run Code Online (Sandbox Code Playgroud)

注意:问题仍然存在于CustomerService.如果我尝试将其从提供程序数组中删除AppModule或清除它的constructor依赖项,那么应用程序运行正常.

任何帮助将不胜感激.

Cle*_*ode 5

我正在使用角度路由器版本

"@angular/router": "3.0.0"
Run Code Online (Sandbox Code Playgroud)

并尝试将其更新为

"@angular/router": "3.1.0"
Run Code Online (Sandbox Code Playgroud)

像魅力一样工作.:)