Home > Net >  Why is the *ngIf statement not working in Angular 13?
Why is the *ngIf statement not working in Angular 13?

Time:11-18

I just created a new Angular 13 project and ran into the issue, that any *ngIf statement is not just ignored, but the whole div is not shown at all. The html file I tested this with looks as follows:

<div *ngIf="true">This is text a</div>
<div>This is text b</div>

and this is the outcome (the console is also empty): website screenshot

I have no idea if this is an issue with Angular 13 or something else, but I welcome any hints or ideas.

CodePudding user response:

Without seeing the code it's difficult to understand the problem. Do you have some console errors?

One reason might be that you are not importing CommonModule in the yourName.module.ts file. In this case you will see an error like "can't bind to ngIf since it isn't a known property of 'div'"

CodePudding user response:

I forgot to import the sub-module (in which the used component was included) into the app.module.ts file. After adding the import everything worked as expected.

I am just curious why the compiler didn't throw an error message of some sorts ...

  • Related