5

enter image description here

I'm new in Angular 2 I need help on the routing part. I'm using http://jasonwatmore.com/post/2016/09/29/angular-2-user-registration-and-login-example-tutorial

I got an error

Exported variable 'routing' has or is using name 'ModuleWithProviders' from external module "/home/frank/angular/node_modules/@angular/core/src/metadata/ng_module" but cannot be named.

Here is my code

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule }    from '@angular/forms';
import { HttpModule } from '@angular/http';

// used to create fake backend
import { fakeBackendProvider } from './_helpers/index';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { BaseRequestOptions } from '@angular/http';

import { AppComponent }  from './app.component';
import { routing }        from './app.routing';

import { AlertComponent } from './_directives/index';
import { AuthGuard } from './_guards/index';
import { AlertService, AuthenticationService, UserService } from './_services/index';
import { HomeComponent } from './home/index';
import { LoginComponent } from './login/index';
import { RegisterComponent } from './register/index';

@NgModule({
    imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    routing
 ],
declarations: [
AppComponent,
AlertComponent,
HomeComponent,
LoginComponent,
RegisterComponent
],
providers: [
    AuthGuard,
    AlertService,
    AuthenticationService,
    UserService,

    // providers used to create fake backend
    fakeBackendProvider,
    MockBackend,
    BaseRequestOptions
],
bootstrap: [AppComponent]
})

 export class AppModule { }

Any ideas on the error? I also tried seimport { ModuleWithProviders } from '@angular/core';tting my "declaration": true, in tsconfig.js and also imported

Paul Samsotha
  • 188,774
  • 31
  • 430
  • 651
Frank Mendez
  • 466
  • 1
  • 10
  • 22

2 Answers2

10

I solved this by doing:

export const routing: ModuleWithProviders = RouterModule.forRoot(APP_ROUTES);

And don't forgot to import ModuleWithProviders from @angular/core

import { ModuleWithProviders } from "@angular/core";
Mingchao Liao
  • 221
  • 1
  • 4
3

You should not need to import ModuleWithProviders. I think that you only needed to import that module in older Release Candiades (RCs). Currently, importing MgModule will automatically allow providers which seems to be the only purpose for ModuleWithProviders DOCS

Nate May
  • 3,383
  • 5
  • 29
  • 75