ng-packagr: Error StaticInjectorError[ViewContainerRef] when having *ngIf or *ngFor // Solution: `--preserve-symlinks`
Type of Issue
[x] Bug Report
[ ] Feature Request
Description
When I am using either *ngIf or *ngFor in my template I got this error message: StaticInjectorError[ViewContainerRef]. Any ideas why this happen?
How To Reproduce
- Create a component
footer.component.ts - Add *ngIf in
footer.component.html - Run
ng-packagr -p ng-package.jsonandnpm publish - Install on new Angular 5 app (
npm install) - Run my Angular 5 App
ng serve
Here is my code:
footer.component.ts
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: 'app-footer',
templateUrl: './footer.component.html',
styleUrls: ['./footer.component.scss']
})
export class FooterComponent implements OnInit {
@Input() isTrue: boolean;
constructor( ) { }
ngOnInit() { }
}
footer.component.html
<footer>
<h2 *ngIf="isTrue">Hello</h2>
</footer>
Expected Behaviour
Should not error
Version Information
ng-packagr: ^1.6.0
node: v7.6.0
@angular: v5.0.2
rxjs: v5.5.2
zone.js: v0.8.18
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 25 (5 by maintainers)
Still facing with
StaticInjectionErroreven with--preserve-symlinksflag. Unfortunately it’s not the solution for*ngIfand*ngForcase.Have you tried the
--preserve-symlinksflag?Hi all,
please check and confirm whether
--preserve-symlinkssolves the issue as it does for the original error (StaticInjectorError). Should it not in your case, please open a separate issue.As mentioned in https://github.com/dominique-mueller/angular-package-builder/issues/38, using the
--aotor--preserve-symlinksflag onng serveprobably solves this issue (which occurs when installing the library via a local directory instead of remotely).UPDATE: I manage to solve the issue by updating both my lib and my app that uses the lib to Angular 5.2.8 (it works with 5.2.9 also) and angular cli to 1.7.3. No preserveSymlinks or any other configuration is needed!
@vapits Could you link an example project with this working? I’m currently still having issues using the Angular 5.2.8 and cli 1.7.3. Maybe there is another package that needs to be a specific version or you have a specific angular/webpack config? My main app will not dynamically load the lib with *ngIf, but loads fine without an *ngIf.
i dont whats it getting wrong but for me following solution works (i facing this in anguiar5) add in angular-cli.json “defaults”: { “styleExt”: “css”, “component”: {}, “build”: { “preserveSymlinks”: true } }
this may help … 😃
@doenikoe did you get this issue fixed?