2017-06-19 58 views
0

我有一個應用程序,其中包含2個模塊:「Shared」和「Web」。Angular:來自共享模塊的組件不被識別

我在網絡中的所有組件都正常工作。我剛剛創建的共享模塊中的一個簡單的組件,因爲我打算重新使用它整個應用程序:

import { Component, Input, OnInit } from '@angular/core'; 

@Component({ 
    selector: 'pb-ds-pluginstable', 
    templateUrl: './pluginstable.component.html', 
    styleUrls: ['./pluginstable.component.scss'] 
}) 
export class PluginstableComponent implements OnInit { 

    @Input() name: string; 
    @Input() version: string; 
    @Input() link: string; 

    constructor() {} 
    ngOnInit() {} 

} 

這是導入共享模塊,並遠銷:

...other imports... 
import { PluginstableComponent } from './pluginstable/pluginstable.component'; 

@NgModule({ 
imports: [ 
    CommonModule, 
    RouterModule, 
    NgbModule 
], 
    declarations: [HeaderComponent, FooterComponent, HeaderShadowDirective, PluginstableComponent], 
    exports: [HeaderComponent, FooterComponent, HeaderShadowDirective, PluginstableComponent] 
}) 
export class SharedModule { } 

但我當在Web模塊中使用的組件的模板,像這樣:

<pb-ds-pluginstable name="foo" version="2.2.2" link="bar"></pb-ds-pluginstable> 

我得到的組件不識別的錯誤:

core.es5.js:1020 ERROR Error: Uncaught (in promise): Error: Template parse errors: 
'pb-ds-pluginstable' is not a known element: 
1. If 'pb-ds-pluginstable' is an Angular component, then verify that it is part of this module. 
2. If 'pb-ds-pluginstable' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. (" 
    </section> 

    [ERROR ->]<pb-ds-pluginstable name="foo" version="2.2.2" link="bar"></pb-ds-pluginstable> 

我在這裏錯過了什麼?

+0

並且您的共享模塊導入到應用程序/根模塊中? – Brandon

+0

是的,它是...... – Steve

+0

嗯。我見過Angular要求我在添加共享模塊時停止我的開發服務器並重新構建項目。我有一個奇怪的緩存問題,有一天刪除的界面掛在...你有沒有嘗試重新啓動你的IDE? – Brandon

回答

0

您也需要導入SharedModule(沒有父母,沒有孩子,確切的說模塊)module,要使用它的出口元素

@NgModule({ 
    imports: [ 
     SharedModule, 
     ... 
    ] 
}) 
export class YourModule { } 
+0

謝謝。對於其他讀者來說,這當然意味着將導入添加到模塊的頂部:'從'../ shared/shared.module'導入{SharedModule};' – Steve

0

我asume,你是不是進口將共享模塊放入Web模塊。很有可能您只將導入添加到應用程序模塊中