我创建了一个 Angular-Library,它在我的 App-Workspace 之外。结果是我有两个不同的工作区。
我的第一种方法是构建我的库并将/dist文件夹与我的应用程序链接起来。这在 ng serve 上效果不佳,但无论如何我在渲染我的 Library-Component-Templates 时遇到了问题。
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'bindingStartIndex' of null
TypeError: Cannot read property 'bindingStartIndex' of null
[...]
Run Code Online (Sandbox Code Playgroud)
在做我的第一次研究时,我发现了这个 github 问题帖子
基本上给定的解决方案是在我的 tsconfig.json 中添加我的库public-api.ts中的路径,该路径可以导入到我的应用程序源中。像这样:
"paths": {
"@app/*": ["src/app/*"],
"@core": ["src/app/@core"],
"@core/*": ["src/app/@core/*"],
"@shared": ["src/app/@shared"],
"@shared/*": ["src/app/@shared/*"],
"@env/*": ["src/environments/*"],
"@myLibrary/*": ["../myLibrary/projects/myLibrary/src/public-api"]
}
Run Code Online (Sandbox Code Playgroud)
不知何故,我在渲染模板时仍然遇到同样的问题。
因此,我的最后一种方法只是直接从我的 app.module.ts 导入我的 lib-Component
import { TestComponent } from '../../../../myLibrary/projects/myLibrary/src/lib/components/testComponent/test.component';
@NgModule({
imports: [
FlexLayoutModule,
CelNgZuiModule,
CommonModule
],
declarations: [FactoryModelComponent, TestComponent,]
}) …Run Code Online (Sandbox Code Playgroud) typescript angular-module angular angular-library angular-ivy