sharedModules分成多个完全不同的应用程序

mol*_*ikh 10 javascript angular-material2 angular

我做了同样的事情: 如何通过Angular 4中的共享模块正确导入Angular Material模块?

除了我想要创建一个类似ui-kit的模板,然后在具有不同位置的不同应用程序中使用它(它们不在同一文件夹中).

目前,我正在这样做,一切正常,除非我尝试在我的sharedComponent中使用库,就像我想要使用:

<button mat-raised-button color="primary">Click me!</button>
Run Code Online (Sandbox Code Playgroud)

角度材料按钮,

angular-cli不会抛出任何错误,我只是在控制台上看到这个错误:

Error: StaticInjectorError[ElementRef]: 
  StaticInjectorError[ElementRef]: 
    NullInjectorError: No provider for ElementRef!
    at _NullInjector.get (core.js:993)
    at resolveToken (core.js:1281)
    at tryResolveToken (core.js:1223)
    at StaticInjector.get (core.js:1094)
    at resolveToken (core.js:1281)
    at tryResolveToken (core.js:1223)
    at StaticInjector.get (core.js:1094)
    at resolveNgModuleDep (core.js:10878)
    at NgModuleRef_.get (core.js:12110)
    at resolveDep (core.js:12608)
BtnComponent.html:3 ERROR TypeError: Cannot read prop
Run Code Online (Sandbox Code Playgroud)

并且通过谷歌搜索找不到任何有用的东西.

任何提示都可能有所帮助

更新:

我创建了一个github存储库,它将重现错误.

https://github.com/molikh/shared-module

我也在角度材料库中写了一个更多解释的问题:https: //github.com/angular/material2/issues/9294#event-1416171140

mol*_*ikh 3

我为我的问题找到了一种解决方案。

我用我的组件构建了一些库,然后将它们安装在我的其他应用程序中。

这是关于它的完整教程:

https://medium.com/@nikolasleblanc/building-an-angular-4-component-library-with-the-angular-cli-and-ng-packagr-53b2ade0701e