2017-09-04 84 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) {} 

到您的自定义模块。