简体   繁体   中英

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

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.

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'"

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM