Angular 2.0路由-TS 2305 ...没有导出的成员'ModulewithProviders' [英] Angular 2.0 routing - TS 2305 ... has no exported member 'ModulewithProviders'

查看:196
本文介绍了Angular 2.0路由-TS 2305 ...没有导出的成员'ModulewithProviders'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注有关js官方angular 2.0教程 ="nofollow">站点,并卡在了路由练习的末尾.该代码上次有效,但是前一天,当我再次在node.js cmd中单击" npm start "时,"错误:TS 2305 ...没有导出的成员'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而不是ModulewithProviders("W"代替"w").

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

您需要在 app.routing.ts

这篇关于Angular 2.0路由-TS 2305 ...没有导出的成员'ModulewithProviders'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆