我想从角度1.4端口的一些结构... ...角度2:误解与进口
我也有一些麻烦。例如,我有这样的结构:
部件 - 是一个模块,客户是一个模块,列表 - 是一个模块。
我有导入模块&组件的麻烦。
我做一个这样的方式:
app.module
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { MaterialModule } from '@angular/material';
import 'hammerjs';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import { ComponentsModule } from './components/components.module';
import { CoreModule } from './core/core.module';
import { ServicesModule } from './services/services.module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
MaterialModule.forRoot(),
ComponentsModule,
CoreModule,
ServicesModule,
NgbModule.forRoot()
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.html
<customer-list></customer-list>
,如果我在这里使用angular2引导:
<ngb-accordion #acc="ngbAccordion" activeIds="ngb-panel-0">
<ngb-panel title="Simple">
<template ngbPanelContent>
demo
</template>
</ngb-panel>
</ngb-accordion>
一切都很好。
components.module
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CustomerModule } from './customer/customer.module';
@NgModule({
imports: [
CommonModule
],
declarations: [],
exports: [CustomerModule]
})
export class ComponentsModule { }
customer.module
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CustomerComponent } from './customer.component';
import { ListComponent } from './list/list.component';
import { ItemComponent } from './list/item/item.component';
@NgModule({
imports: [
CommonModule
],
declarations: [CustomerComponent, ListComponent, ItemComponent],
exports: [CustomerComponent, ListComponent]
})
export class CustomerModule { }
list.module
import { NgModule } from '@angular/core';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import { CommonModule } from '@angular/common';
import { ListComponent } from './list.component';
import { ItemComponent } from './item/item.component';
@NgModule({
imports: [
CommonModule,
NgbModule
],
declarations: [ListComponent, ItemComponent],
exports: [ListComponent]
})
export class CustomerModule { }
list.component.html
<ngb-accordion #acc="ngbAccordion">
<ngb-panel >
<template ngbPanelContent>
test
</template>
</ngb-panel>
</ngb-accordion>
在这里,我得到错误:
zone.js:388Unhandled Promise rejection: Template parse errors: 'ngb-panel' is not a known element:
但是,如果我每个模块中导入NgbModule
,直到我达到app.module - 一切都很好。但这很荒谬。
是否有任何可能性,组织角2导入模块,所以,我不需要在每个模块中导入它们,一旦导入到根中 - 我可以在嵌套模块中重用它们,就像它在角1.4(使用ngInject)?
如果你只在'ListModule'中使用'NgbModule',那么你只需要在那里导入它。你是对的:)也许是一个很长的镜头,但是''这个额外的空间可能会成为问题吗? –
PierreDuc
@PierreDuc 似乎它没有帮助( – brabertaser19