2017-09-15 75 views
0

很經典的情況下,我嘗試另一個模塊中使用的一些組件:angular2「不是一個已知的元素」的錯誤:一切都試過

外來元件:

import { Component, ViewEncapsulation, 
    ElementRef, ViewChild, Input, Output, 
    EventEmitter } from '@angular/core'; 

declare var __moduleName: string 

@Component({ 
    moduleId: __moduleName, 
    selector: 'bidule', 
    templateUrl: 'bidule.html', 
    styleUrls: [], 
    encapsulation: ViewEncapsulation.None 
}) 
export class BiduleComponent { 

    @Input() config: { } 

    constructor(protected elRef: ElementRef) { 
    } 

} 
// template : <p>basic text</p> 

外國模塊:

import { NgModule }  from '@angular/core'; 
import { CommonModule } from '@angular/common'; 

import { BiduleComponent } from './bidule' 

@NgModule({ 
    imports: [ 
    ], 
    declarations: [ 
    BiduleComponent 
    ], 
    exports: [ 
    BiduleComponent 
    ] 
}) 
export class BiduleModule {} 

主要成分:

... 
import { BiduleComponent }  from '../../bidule/bidule' 
... 
// template : <bidule></bidule> 

主要模塊:

import { BiduleModule }   from '../../bidule/module' 
// ... 
@NgModule({ 
    imports: [ 
    // ... 
    BiduleModule 
    ] 
}) 

我相信我檢查一切:

https://stackoverflow.com/questions/44429996#44430230

如果您有任何想法。提前致謝。

(bidule是thingamajig一個法語單詞)

回答

0

你只需要導入外部模塊的主要模塊,並使用<bidule></bidule>主模塊的任何組件。 你是對的,出口BiduleComponent,但你不需要直接導入到主要組件,這足以導入外部模塊到主模塊。

+0

確實有疑問;我嘗試了/不。 – spin

+0

問題仍然存在或您解決了它? – macvg

+0

它仍然存在,否則我會驗證您的答案:) – spin

相關問題