简体   繁体   English

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

[英]sharedModules into multiple completely different apps

I did the same thing he did here: How to correctly import the Angular Material module through a shared module in Angular 4? 我做了同样的事情: 如何通过Angular 4中的共享模块正确导入Angular Material模块?

Except that I want to create an ui-kit like template then use it in different apps with different locations(they are not in same folder). 除了我想要创建一个类似ui-kit的模板,然后在具有不同位置的不同应用程序中使用它(它们不在同一文件夹中)。

Currently, I'm doing that and everything works fine except when I try to use library inside my sharedComponent, like when I want to use : 目前,我正在这样做,一切正常,除非我尝试在我的sharedComponent中使用库,就像我想要使用时:

<button mat-raised-button color="primary">Click me!</button>

angular material button, 角度材料按钮,

angular-cli doesn't throw any error , I just see this error on console: 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

and couldn't find anything useful by googling. 并且通过谷歌搜索找不到任何有用的东西。

any tips can be helpful 任何提示都可能有所帮助

update: 更新:

i have created a github repository that will reproduce error. 我创建了一个github存储库,它将重现错误。

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

i have wrote an issue with more explanation in angular material repository too : https://github.com/angular/material2/issues/9294#event-1416171140 我也在角度材料库中写了一个更多解释的问题: https//github.com/angular/material2/issues/9294#event-1416171140

I found one solution for my problem. 我找到了解决问题的方法。

I build some libraries out of my components and then installed them inside my other apps. 我从我的组件中构建了一些库,然后将它们安装在我的其他应用程序中。

Here is a complete tutorial about it : 这是一个完整的教程:

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

In my case, the problem was that I had not imported BrowserModule in my package module from which I was exporting the directive so all I did was to import it and add it to imports array 在我的情况下,问题是我没有在我导出指令的包模块中导入BrowserModule所以我所做的就是导入它并将其添加到导入数组

Like this 像这样

import { NgModule } from '@angular/core';
import { myDirective } from './my.directive';
import { BrowserModule } from '@angular/platform-browser';

@NgModule({
  imports: [BrowserModule
  ],
  declarations: [myDirective],
  exports: [myDirective],
})
export class ImageHelperModule { }

I expressed the same same problem, when I tried to import module from sub-project which have its own node_modules directory. 当我尝试从具有自己的node_modules目录的子项目中导入模块时,我也表达了同样的问题。 Building of the library into ./dist directory of "host" project and importing from there solves the issue. 将库构建到“host”项目的./dist目录并从那里导入解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在一个页面上运行具有不同角度版本的多个应用程序? - Is it possible to run multiple apps with different angular versions on one page? 在不同VS解决方案中的多个应用程序中使用的自定义控件 - custom control to be used in multiple apps that are in different VS solutions 如何在sharedModules angular 中更改primeng 库 - How to change primeng library in sharedModules angular 如何在不同服务器中托管的多个Angular.js应用程序之间实现资产共享 - How to acheive sharing assets between multiple Angular.js apps hosted in different servers 在同一域但不同子域中的多个javascript应用程序之间共享Localstorage令牌 - Sharing Localstorage token amongst multiple javascript apps on same domain but different subdomains RSS Feed与浏览器中的显示完全不同 - RSS Feed completely different to how displayed in Browser 矩格式后,它显示出完全不同的值 - After moment format it shows completely different value fitBounds和extends-显示在一个完全不同的地方 - fitBounds and extend - showing up at a completely different place Joi:如何验证 2 arrays 完全不同 - Joi: how to validate that 2 arrays are completely different ExpressJS-在同一Express服务器上为具有不同基本目录的多个Web应用程序提供服务 - ExpressJS - Serving Multiple Web Apps with Different Base Directories on the Same Express Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM