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?
{ provide: Router, useClass: RouterModule}it should work, given you added theAppRoutingModuleto the app module imports. Other than that, please try and provide a Plunker for better help.{ provide: Router, useClass: RouterModule}and got the error. Then I looked at stackoverflow.com/questions/39015918/… and began adding{ provide: Router, useClass: RouterModule}but it didn't help either. So by removing{ provide: Router, useClass: RouterModule}I would still be getting the error. It must be something else I may have missed?