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.

Cannot create property 'ngIf' on number in Angular 8

See original GitHub issue

🐞 bug report

Affected Package

@angular/core

Is this a regression?

I can’t tell exactly, this app is freshly written in angular 8, but I’ve never encountered such issues in previous versions.

Description

ngIf behaves unexpectedly, I have a complex component which consists of multiple smaller components, but still template reaches up to 70 lines. There I have bindings on every component and at the top of the template I have this code:

<h2>
    <span *ngIf="hasBasicInfo(); else missing">
      {{ form.value[basicInfoFormControlName][nameControlName] }}
    </span>
    <ng-template #missing>MISSING</ng-template>
  </h2>

This works perfectly fine until I changed one of subcomponents, which in template looked like this:

<st-classification-in-frameworks
              [solution]="solution"
              [selectedSegments]="solution.segments"
              (segmentSelectionChange)="updateSolutionOnSegmentSelection($event)"
></st-classification-in-frameworks>

Basically I just deleted [selectedSegments]="solution.segments" like and removed an @Input() in that component. As soon as I do that I get error: Cannot create property 'ngIf' on number 871548 It complains exactly about that ngIf I mentioned above. I believe this is a bug in the core rendering(I am using Ivy), because for some reason instance in setInputsForProperty is evaluated as a number, and not only that, sometimes I am also getting boolean value. This appears to be pretty random, because when I remove else part from that ngIf it works again, or if I move it another place. I don’t see how my code can be wrong to break it. But I also don’t have knowledge of how Ivy works from inside to understand why this happens.

πŸ”¬ Minimal Reproduction

Unfortunately I was not able to reproduce this in any other setup, this issue seems to be pretty specific and quite random.

πŸ”₯ Exception or Error




core.js:7187 ERROR TypeError: Cannot create property 'ngIf' on number '871548'
    at setInputsForProperty (core.js:13500)
    at elementPropertyInternal (core.js:12390)
    at Module.Ι΅Ι΅property (core.js:16528)
    at SolutionComponent_Template (solution.component.html:3)
    at executeTemplate (core.js:12007)
    at checkView (core.js:13358)
    at componentRefresh (core.js:13122)
    at refreshChildComponents (core.js:11710)
    at refreshDescendantViews (core.js:11616)
    at renderComponentOrTemplate (core.js:11985)

🌍 Your Environment

Angular Version:




Angular CLI: 8.0.0
Node: 10.16.0
OS: darwin x64
Angular: 8.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.0
@angular-devkit/build-angular     0.800.0
@angular-devkit/build-optimizer   0.800.0
@angular-devkit/build-webpack     0.800.0
@angular-devkit/core              8.0.0
@angular-devkit/schematics        8.0.0
@ngtools/webpack                  8.0.0
@schematics/angular               8.0.0
@schematics/update                0.800.0
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.30.0

Anything else relevant?

One more detail is that the error doesn’t happen on initial load of the component. First time it renders correctly, however if hasBasicInfo returns false, it does not render the missing template. Then I click on something that triggers change detection and that error appears. What is interesting is that it only appears twice(for ngIf and ngIfElse, which I could while trying to debug) with different property and third time it actually runs.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
BlindDespaircommented, Jul 17, 2019

I’ll try to create an app where this would be reproducible when I have time. Hopefully this week.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 22, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't bind to 'ngIf' since it isn't a known property of 'div'
angular - Can't bind to 'ngIf' since it isn't a known property of 'div' - Stack Overflow. Stack Overflow for Teams – Start...
Read more >
Angular ngIf: Complete Guide
In this post, we are going to cover all the features that we have available for using the Angular ngIf core directive.
Read more >
Understanding template variables - Angular
In most cases, Angular sets the template variable's value to the element on which it occurs. In the previous example, phone refers to...
Read more >
Understanding *ngif directive & "*ngIf else then" in Angular
Now we will learn how to write *ngIf else in Angular. As explained above, we need to declare an else block. We will...
Read more >
48 answers on StackOverflow to the most popular Angular ...
Angular no provider for NameService; Binding select element to ... Can't bind to 'ngForIn' since it isn't a known native property; *ngIf andΒ ......
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