我正在玩Angular2,并试图让一个模块(BreadcrumbDemoModule
)导入另一个(BreadcrumbModule
)的组件.
目前,BreadcrumbModule只包含一个组件:ng2-breadcrumb
.但是,当我尝试使用此组件时BreadcrumbDemoModule
,我收到错误消息:
'ng2-breadcrumb'不是已知元素.
我想我必须在某个地方错过一条线,并希望有人可以向我指出我做错了什么.
非常感谢你提前!
BreadcrumbModule的文件
breadcrumb.component.html:
THIS IS A BREADCRUMB TEST
breadcrumb.component.ts:
import { Component } from '@angular/core'; @Component({ selector: 'ng2-breadcrumb', template: require('./breadcrumb.component.html') }) export class BreadcrumbComponent {}
组件/面包屑/ index.ts:
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BreadcrumbComponent } from './breadcrumb.component'; @NgModule({ imports: [ BrowserModule //for later use ], declarations: [ BreadcrumbComponent ] }) export class BreadcrumbModule {}
BreadcrumbDemoModule的文件
面包屑demo.component.html:
面包屑demo.component.ts:
import { Component } from '@angular/core'; import { BreadcrumbModule } from './../index'; @Component({ selector: 'ng2-breadcrumb-demo', template: require('./breadcrumb-demo.component.html') }) export class BreadcrumbDemoComponent {}
组件/面包屑/演示/ index.ts:
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BreadcrumbModule } from './../index'; import { BreadcrumbDemoComponent } from './breadcrumb-demo.component'; @NgModule({ imports: [ BreadcrumbModule, BrowserModule, ], declarations: [ BreadcrumbDemoComponent ] }) export class BreadcrumbDemoModule {}
PierreDuc.. 18
您必须将其添加BreadcrumbComponent
到exports数组:
@NgModule({ imports: [ BrowserModule //for later use ], declarations: [ BreadcrumbComponent ], exports: [ BreadcrumbComponent ] }) export class BreadcrumbModule {}
declarations
数组内部的内容是模块本身使用的组件/指令/管道.如果要将这些模块公开给导入模块的其他模块,则应将它们添加到exports
数组中
您必须将其添加BreadcrumbComponent
到exports数组:
@NgModule({ imports: [ BrowserModule //for later use ], declarations: [ BreadcrumbComponent ], exports: [ BreadcrumbComponent ] }) export class BreadcrumbModule {}
declarations
数组内部的内容是模块本身使用的组件/指令/管道.如果要将这些模块公开给导入模块的其他模块,则应将它们添加到exports
数组中