简体   繁体   中英

Angular 2.0 routing - TS 2305 … has no exported member 'ModulewithProviders'

I'm following a angular 2.0 tutorial on angular js official site and got stuck at the end of the routing excercise. The code worked last time but the other day when i hit ' npm start ' in the node.js cmd again, the " error: TS 2305 ... has no exported member 'ModulewithProviders '" popped up despite the whole files left untouched.

Here's the code in the same app folder:

main.ts:

import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);

app.module.ts

import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {AppComponent} from './app.component';
import {HeroesComponent} from './heroes.component';
import {DashboardComponent} from './dashboard.component';
import {routing} from './app.routing';
import {FormsModule} from '@angular/forms';

@NgModule({
    imports: [BrowserModule,FormsModule,routing],
    declarations: [AppComponent, HeroesComponent, DashboardComponent],
    bootstrap: [AppComponent],
})

export class AppModule {}

app.component.ts

import {Component} from '@angular/core';

@Component({
    selector: 'my-app',
    template: `
        <h1>{{title}}</h1>
        <nav>
        <a routerLink="/heroes">Heroes</a>
        <a routerLink="/dashboard">Dashboard</a>
        </nav>
        <router-outlet></router-outlet>
    `
})
export class AppComponent{
    title: string = "Tour of heroes"
}

heroes.component.ts

import {Component} from '@angular/core';

@Component({
    selector: 'hero-component',
    template: `<div>Heroes </div>`
})
export class HeroComponent{};

dashboard.component.ts

import {Component} from '@angular/core';

@Component({
    selector: 'dashboard-component',
    template: `<div>Dashboard </div>`
})
export class DashboardComponent{};

app.routing.ts

import { ModulewithProviders } from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {HeroesComponent} from './heroes.component';
import {DashboardComponent} from './dashboard.component';

const appRoutes: Routes = [
    {
        path: 'heroes',
        component: HeroesComponent
    },
    {
        path: 'dashboard',
        component: DashboardComponent
    },
    {
        path: '',
        redirectTo: '/dashboard',
        pathMatch: 'full'
    }
]
export const routing: ModulewithProviders = RouterModule.forRoot(appRoutes);

ModuleWithProviders instead of ModulewithProviders ('W' instead of 'w').

You need to change it in both places in app.routing.ts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM