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);
答案 0 :(得分:2)
ModuleWithProviders
代替ModulewithProviders
('W'代替'w')。
您需要在 app.routing.ts
中的两个位置进行更改