I created an Angular-Library which is outside of my App-Workspace. The result is that I have two different workspaces.
My first approach was building my Library and link /dist folder with my App. This worked not so fine with ng serve but anyways I had an issue with rendering my Library-Component-Templates.
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'bindingStartIndex' of null
TypeError: Cannot read property 'bindingStartIndex' of null
[...]
Doing my first research I found this github issues post
Basically the given solution is to add my path from my Library public-api.ts in my tsconfig.json which can be imported inside my App sources. Like this:
"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"]
}
Somehow I still have the same issue while rendering my template.
Because of that my last approach was just simply import my lib-Component directly from my app.module.ts
import { TestComponent } from '../../../../myLibrary/projects/myLibrary/src/lib/components/testComponent/test.component';
@NgModule({
imports: [
FlexLayoutModule,
CelNgZuiModule,
CommonModule
],
declarations: [FactoryModelComponent, TestComponent,]
})
And the result is the same. I still get the same error while rendering my template. And this approach is currently confusing me really. I mean I just only imported a .ts-File from another Location. Using components from my App or injecting Services from my Library are working fine.
Test.component
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'cel-test',
template: '<p> should work fine </p>',
})
export class TestComponent implements OnInit {
constructor() {
console.log("it is working");
}
ngOnInit() {
}
}
App-angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"mes-demo": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"preserveSymlinks": true,
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/apple-touch-icon.png",
"src/robots.txt",
"src/manifest.webmanifest",
"src/assets"
],
"styles": [
"src/main.scss"
],
"scripts": []
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": true,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
],
"serviceWorker": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
},
"ci": {
"progress": false
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "mes-demo:build",
"hmr": true,
"hmrWarning": false
},
"configurations": {
"production": {
"browserTarget": "mes-demo:build:production",
"hmr": false
},
"ci": {
"progress": false
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "mes-demo:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"scripts": [],
"styles": [
"src/main.scss"
],
"assets": [
"src/favicon.ico",
"src/apple-touch-icon.png",
"src/robots.txt",
"src/manifest.webmanifest",
"src/assets"
]
},
"configurations": {
"ci": {
"progress": false,
"watch": false
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "mes-demo:serve"
},
"configurations": {
"production": {
"devServerTarget": "mes-demo:serve:production"
}
}
}
}
}
},
"defaultProject": "mes-demo"
}