angular - Angular 库 - NullInjectorError: StaticInjectorError(AppModule)[NgClassImpl -> ElementRef]
问题描述
我确实有问题。我正在 Angular 库中构建一个组件:
<button
class="btn btn-white btn-home"
[class]="getClassBySeverity()"
[disabled]="disabled"
[hidden]="!renderer"
[ngClass]="{ uppercase: uppercase }"
[type]="type"
[style.color]="labelColor"
[style.backgroundColor]="backgroundColor"
>
<span [hidden]="!hasIcon()">
<span
[ngClass]="{ 'btn-icon-left': icon }"
[hidden]="!isLeftPosition()"
[class]="icon"
></span
>{{ label
}}<span
[hidden]="isLeftPosition()"
[ngClass]="{ 'btn-icon-right': icon }"
[class]="icon"
></span>
</span>
<span [hidden]="hasIcon()">{{ label }}</span>
</button>
但是当我在我的应用程序中嵌入这个组件时,我得到了:
错误 NullInjectorError: StaticInjectorError(AppModule)[NgClassImpl -> ElementRef]: StaticInjectorError(Platform: core)[NgClassImpl -> ElementRef]: NullInjectorError: 没有提供 ElementRef!
发生这种情况是因为ngClass。
如果我在应用程序中构建我的组件,它工作正常。
我在 github 的一个问题中看到我需要将preserveSymlinks放在我的tsconfig.lib.json中:
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true,
"preserveSymlinks": true
}
但无论如何它都不起作用。
任何人都知道在 Angular 中构建库的正确方法吗?
谢谢!
解决方案
推荐阅读
- r - 使用 R 函数创建序列
- go - 模板化可用于生成新代码的 Go 代码
- python - 使用正则表达式的错误 - 预期的字符串或类似字节的对象
- flutter - Flutter 如何在网格上的 TextFields 之间切换焦点(填字游戏)
- r - 在R中命名矩阵中的行
- javascript - 如何让访问我的站点的客户端发出另一个请求并在初始请求中使用其响应数据?
- python - Scrapy request get some responses, but not all
- php - 将 PHP 变量设置为 JSON 对象中的值
- wix - Wix:是否可以从控制面板的“添加/删除程序”中删除捆绑条目?
- docker - appId: error.pattern 在 Marathon 中创建应用程序时