ngIf cryptic error when a then block is set to a non template
See original GitHub issueEdit (vicb) - the error is caused by the ngIf
<p *ngIf="user.removed; else activeBlock">User had been removed: {{user.removed | date : 'dd.MM.yyyy'}}</p>
<p #activeBlock>User is active</p>
The second <p>
should be a <ng-template>
but the error message does not help
Hi. Probably i found an error.
I’ve used ngIf block inside ngFor block also inside ngFor block placed another ngFor.
Like this:
<tr *ngFor="let user of users">
<td>
<p *ngFor="let login of users.logins">{{login}}</p>
</td>
<td>
<p *ngIf="user.removed; else activeBlock">User had been removed: {{user.removed | date : 'dd.MM.yyyy'}}</p>
<p #activeBlock>User is active</p>
</td>
</tr>
And this throws error: templateRef.createEmbeddedView is not a function
I’m using this code now (instead previous):
<tr *ngFor="let user of users">
<td>
<p *ngFor="let login of users.logins">{{login}}</p>
</td>
<td>
<p *ngIf="user.removed">User had been removed: {{user.removed | date : 'dd.MM.yyyy'}}</p>
<p *ngIf="!user.removed">User is active</p>
</td>
</tr>
Thanks for attention.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:9 (3 by maintainers)
Top Results From Across the Web
ngIf getting error on block that get false - Stack Overflow
First of all fix your ngIf attribute with quotes: *ngIf="userData?.isAuth". The problem is, that | is used for pipes in templates and the ......
Read more >Angular. ngIf then/else block shows the error (statement ...
i.e. there is no semicolon after thenblock. But https://angular.io/api/common/NgIf#using-non-inlined-then-template shows a different syntax. Both ...
Read more >Why your Angular App is not Working: 11 common Mistakes
When your angular app is not working and all it gives you are some cryptic red lines in a console. Especially when you...
Read more >NgIf - Angular
A structural directive that conditionally includes a template based on the value of an expression coerced to Boolean. When the expression evaluates to...
Read more >Cisco Nexus 7000 Series NX-OS Release Notes, Release 8.x
VLAN translation on fabric extender is not supported. If you need to map a VLAN, you must move the interface to the parent...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi!
Try to put your
else
block into an<ng-template></ng-template>
block as it shown in the changelog Like this:@titusfx In short, yes.
The *ngIf directive is a structural directive with the asterisk character * being a syntatic sugar, and it expects you to pass
<ng-template>
for the else condition’sTemplateRef
in the ngIf directive code to grab the referenced markup correctly. When you write<div *ngIf="showThis">Test</div>
, it really becomes this:And when you write this:
It gets desugared to something like this (I’m not 100% sure on this desugaring):
For more info, read these sections: https://angular.io/guide/structural-directives#what-are-structural-directives and https://angular.io/guide/structural-directives#the-asterisk--prefix.