2
我是Angular2新手,我有一些im(ex)移植模塊的困難。使用來自核心模塊的組件
根據官方的風格指南CoreModule是:
CoreModule - import once when the app starts and never import anywhere else.
這是否意味着從核心模塊的所有那些出口的東西將是唯一可用的在它只是導入模塊?沒有辦法讓這些東西在某些子模塊中可用?我創建虛擬項目只是爲了測試此行爲:
虛設部件:
@Component({
selector: 'dummy-component',
template: '<h4>Dummy component</h4>',
})
export class DummyComponent {}
核心模塊:
import { DummyComponent } from './dummy.component';
@NgModule({
declarations : [DummyComponent],
exports : [DummyComponent]
})
export class CoreModule {}
應用模塊(根模塊):
@NgModule({
declarations: [AppComponent,],
imports: [BrowserModule, CoreModule, HomeModule, RoutingModule],
exports : [CoreModule],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
首頁模塊宣佈家庭組件:
@Component({
selector: 'home-component',
template:
`
<h2>Home component</h2>
<dummy-component></dummy-component>
`
})
export class HomeComponent {}
當我嘗試運行此代碼,我得到這個錯誤:如果你想在其他模塊的東西
'dummy-component' is not a known element