【发布时间】:2017-05-02 00:23:00
【问题描述】:
我想从 angular 1.4 移植一些结构...
我有一些麻烦。例如我有这样的结构:
components - 是一个模块,customer 是一个模块,list - 是一个模块。
我在导入模块和组件时遇到问题。
我是这样做的:
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 拒绝:模板解析错误: 'ngb-panel' 不是已知元素:
但是如果我在每个模块中导入NgbModule,直到我到达 app.module - 一切都很好。但这太荒谬了。
有没有可能以 Angular 2 组织模块的导入,所以,一旦在根目录中导入,我就不需要在每个模块中导入它们 - 我可以在嵌套模块中重用它们,就像在 Angular 中一样1.4(使用 ngInject)?
【问题讨论】:
-
如果您只在
ListModule中使用NgbModule,那么您只需将其导入那里。你说得对 :) 可能有点远,但是<ngb-panel >中的额外空间会不会是问题所在? -
@PierreDuc 似乎没有帮助(
标签: angular typescript