gpt4 book ai didi

javascript - Angular 2.0 路由 - TS 2305 ...没有导出成员 'ModulewithProviders'

转载 作者:行者123 更新时间:2023-11-29 14:40:17 25 4
gpt4 key购买 nike

我正在关注 Angular js 官方的 angular 2.0 教程 site并卡在路由练习的末尾。该代码上次有效,但前几天我再次在 node.js cmd 中点击“npm start”时,“error: TS 2305 ... has no exported member 'ModulewithProviders'"尽管整个文件都保持原状,但还是弹出了。

这是同一个应用文件夹中的代码:

ma​​in.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 而不是 ModulewithProviders('W' 而不是 'w')。

您需要在 app.routing.ts

的两个地方更改它

关于javascript - Angular 2.0 路由 - TS 2305 ...没有导出成员 'ModulewithProviders',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39218802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com