Shawn
Shawn

Reputation: 5260

(SystemJS) Can't resolve all parameters for Router in Angular 2.1.2

I am upgrading from RC4 to 2.1.2. I understand that ROUTER_DIRECTIVES is deprecated. So in my LoginComponent now looks like this

import {Component,Injectable} from '@angular/core';
import {Router,RouterModule} from '@angular/router';
import {FormBuilder, Validators, FormGroup, FormsModule} from '@angular/forms';
import {AuthService} from './auth.service';

@Component({
  selector: 'login',
  templateUrl: 'app/login/auth.login.html',
  styleUrls:  ['app/login/auth.login.css'],
  providers: [FormBuilder, AuthService, { provide: Router, useClass: RouterModule} ]
})
@Injectable()
export class LoginComponent {
  form: FormGroup;

  constructor(fb: FormBuilder, 
              private authSvc: AuthService, 
              private router: Router
              ) {....}

In app.routing.module.ts I have

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
  providers: [ AuthGuard,  ]
})
export class AppRoutingModule { }

Then I am getting error as follows

[email protected]?main=browser:232 Error: (SystemJS) Can't resolve all parameters for Router: (?, ?, ?, ?, ?, ?, ?, ?).(…)

I have tried moved { provide: Router, useClass: RouterModule} to app.routing.module.ts but it didn't help.

In RC4 we used directives: [ROUTER_DIRECTIVES] in root component and everything is taken care of. How do I use RouterModule to make Router resolved by the compiler?

Upvotes: 0

Views: 1261

Answers (1)

Daniel Kucal
Daniel Kucal

Reputation: 9232

Just import RouterModule.forRoot(routes) in AppModule and RouterModule in other modules using Router. Don't put into component's providers, AppRoutingModule also seems unnecessary.

Upvotes: 1

Related Questions