question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error StaticInjectorError[ViewContainerRef] when having *ngIf or *ngFor // Solution: `--preserve-symlinks`

See original GitHub issue

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?

screen shot 2017-11-22 at 5 48 52 pm

How To Reproduce

  1. Create a component footer.component.ts
  2. Add *ngIf in footer.component.html
  3. Run ng-packagr -p ng-package.json and npm publish
  4. Install on new Angular 5 app (npm install)
  5. 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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:25 (5 by maintainers)

github_iconTop GitHub Comments

10reactions
dskyyycommented, Jan 26, 2018

Still facing with StaticInjectionError even with --preserve-symlinks flag. Unfortunately it’s not the solution for *ngIf and *ngFor case.

6reactions
dominique-muellercommented, Jan 23, 2018

Have you tried the --preserve-symlinks flag?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular custom library ngFor and ngIF error - Stack Overflow
In your angular.json locate build property under the architect, and in options add "preserveSymlinks": true I think this will solve your problem ...
Read more >
Bountysource
Error StaticInjectorError [ViewContainerRef] when having *ngIf or *ngFor // Solution: `--preserve-symlinks`
Read more >
I Am Facing The Issue In Angular 5 . *Ngfor Not Working ...
Error StaticInjectorError [ViewContainerRef] when having *ngIf or *ngFor // Solution: --preserve-symlinks #304. Closed. doenikoe opened this ...
Read more >
How to use ngfor,ngif together on same element in angular
In Angular,To use ngfor and ngif together on same element place the *ngIf on a parent element ... The above code returns following...
Read more >
Staticinjectorerror(appmodule angular 6), 承诺错误staticinjectorerror ...
Error StaticInjectorError [ViewContainerRef] when having *ngIf or *ngFor // Solution: `--preserve-symlinks` Add import { HttpModule } from '@angular/http'; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found