5

ここに画像の説明を入力

私は Angular 2 の初心者で、ルーティング部分について助けが必要です。http://jasonwatmore.com/post/2016/09/29/angular-2-user-registration-and-login-example-tutorialを使用しています

エラーが発生しました

エクスポートされた変数「ルーティング」は、外部モジュール「/home/frank/angular/node_modules/@angular/core/src/metadata/ng_module」からの名前「ModuleWithProviders」を持っているか、使用していますが、名前を付けることができません。

これが私のコードです

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 { }

エラーに関するアイデアはありますか?また、「@angular/core」から seimport { ModuleWithProviders } を試してみました。tsconfig.js で「宣言」を true に設定し、インポートも行いました。

4

2 に答える 2

10

私はこれを解決しました:

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

@angular/core から ModuleWithProviders をインポートすることを忘れないでください。

import { ModuleWithProviders } from "@angular/core";
于 2016-12-16T07:00:07.177 に答える
3

インポートする必要はありませんModuleWithProviders。そのモジュールを古い Release Candiades (RC) にインポートするだけでよかったと思います。現在、インポート すると、 DOCSMgModuleの唯一の目的と思われるプロバイダーが自動的に許可されます。ModuleWithProviders

于 2016-12-15T03:34:49.973 に答える