1
角度2還在繼續學習。 據我已閱讀有關在Angular 2中使用模塊,並在應用程序中導入它們是他們與他們的孩子共享。在下面的代碼中,我試圖共享ReactiveFormsModule應用程序,但編譯時應用程序崩潰。 我確實使用forRoot方法完成了我的自定義模塊,但我無法理解如何使用內置的ngModules來完成此操作。Angular 2中的導入模塊只能使用一次
app.module.ts
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { ReactiveFormsModule } from '@angular/forms';
import { AppRoutingModule } from "./app-routing.module"
import { AppComponent } from './app.component';
import { HomeModule } from "./home/home.module";
import { AuthenticationModule } from "./authentication/authentication.module";
import { APIServiceModule } from './services/api-service.module';
@NgModule({
imports: [HttpModule,
ReactiveFormsModule,
AppRoutingModule,
AuthenticationModule,
HomeModule,
APIServiceModule.forRoot()
],
declarations: [
AppComponent
],
bootstrap: [AppComponent],
})
export class AppModule { }
authentication.module.ts
import { NgModule } from "@angular/core";
import { BrowserModule } from '@angular/platform-browser';
import { AuthenticationComponent } from "./authentication.component";
import { AuthenticationRoutingModule } from "./authentication-routing.module"
@NgModule({
imports: [AuthenticationRoutingModule, BrowserModule],
declarations: [AuthenticationComponent]
})
export class AuthenticationModule { }
AuthenticationModule
導入在AppModule
欲活性形式模塊跨模塊共享。但編譯時失敗。
雖然大多數在線示例都是關於導出組件的,但您可以實際導出模塊以及組件。 – windmaomao