2017-09-04 125 views
0

我在Angular 4 +材料上編寫自定義庫,我有很多問題。 自定義組件之一是SearchComponent。沒什麼困難。MdCommonModule自定義角度4模塊與材料

search.component.ts

@Component({ 
selector: 'cis-search', 
templateUrl: './search.component.html', 
styleUrls: ['./search.component.scss'], 
encapsulation: ViewEncapsulation.None, 
host: { 
    'class': 'search' 
}}) 
export class CisSearchComponent implements OnChanges {} 

模塊

@NgModule({ 
imports: [ 
    CommonModule, 
    MdIconModule, 
    MdListModule, 
    BrowserAnimationsModule, 
    HttpModule 
], 
providers: [SearchService], 
declarations: [CisSearchComponent], 
exports: [CisSearchComponent] 
}) 
export class CisSearchModule {} 

並打包該模塊彙總。 在主要項目中,我寫

{ 
    provide: DOCUMENT, useValue: {value: document} 
} 

錯誤

TypeError: this._document.createElement is not a function 
at MdCommonModule._checkTheme (material.es5.js:191) 
at new MdCommonModul 

如何解決? 安裝了@latest的所有依賴項。

回答

1

的解決方案是

constructor(@Optional() @Inject(DOCUMENT) private _document: any) {} 

到您的自定義模塊。