DEV Community

Cover image for The Angular Standalone Component Gotcha I Didn’t See Coming

The Angular Standalone Component Gotcha I Didn’t See Coming

Avinash Dalvi on April 28, 2025

Hello Devs, You know that moment when everything looks fine — no errors, no warnings — but the UI just... doesn’t do what it’s supposed to? That’s...
Collapse
 
avelenivius profile image
Rafał (Lenivius)

So did you code this example in Notepad++ or something? Because I also found myself in a similar situation, but I was displayed with a clear console error telling me, that I have a missing import in the component 🤔

Collapse
 
avinashdalvi_ profile image
Avinash Dalvi This is Angular

I used vscode. Didn’t show any error. I tried multiple triage then landed to solution.

Collapse
 
alexilins profile image
alexilins

Actually you don't even need to import CommonModule.
Besides other things - Angular now uses new built-in control flow, all structural directives now follow new syntax.
Your scenario works because of backward compatibility, but is not recommended for new applications.
In your case here what you need to use - angular.dev/api/core/@for .
So, you can rid of importing CommonModule, make your components lighter and more performant.

Collapse
 
avinashdalvi_ profile image
Avinash Dalvi This is Angular

Do you have any example for reference to look ?

Collapse
 
alexilins profile image
alexilins

Yeah, i would recommend this articles about new control flow:
blog.angular-university.io/angular...
blog.angular-university.io/angular...
blog.angular-university.io/angular...
blog.angular-university.io/angular...
Also, it could be helpful to use official schematic to migrate existing codebase - angular.dev/reference/migrations/c...

Thread Thread
 
avinashdalvi_ profile image
Avinash Dalvi This is Angular

Thanks for references.

Collapse
 
georgmu profile image
Georg Müller
<ul>
  @for (option of filterOptions; track $index) {
    <li>{{ option }}</li>
  }
</ul>
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
avinashdalvi_ profile image
Avinash Dalvi This is Angular

Tried this and its works fine.

Collapse
 
georgmu profile image
Georg Müller

When using the new template control flow syntax (@for instead of *ngFor, etc. ...), you dont need the CommonModule import anymore:
angular.dev/guide/templates/contro...

Collapse
 
avinashdalvi_ profile image
Avinash Dalvi This is Angular

Sure I will try for this. is require to upgrade Angular version for this ?

Collapse
 
georgmu profile image
Georg Müller

You need at least Angular 17 for this

Thread Thread
 
avinashdalvi_ profile image
Avinash Dalvi This is Angular

I am using 18 will surely give it try. Thanks

Collapse
 
amjad_yahya_90d727dcadf48 profile image
Amjad Yahya

In my case, if I used *ngFor without importing commonModule, my IDE, in this case Webstorm, would immediately warn me that *ngFor is not defined. And in most cases when I start to write *ngFor it would open a context menu prompting me to import the missing ngFor directive.

Collapse
 
avinashdalvi_ profile image
Avinash Dalvi This is Angular

Updated blog with latest changes. Thanks for recommendation.

Collapse
 
mana95 profile image
Manoj Prasanna 🚀

When developing an application, is it acceptable to build it without a standalone mode? What are your thoughts on this?

Collapse
 
avinashdalvi_ profile image
Avinash Dalvi This is Angular

Standalone is choice which you need to make while developing based on your requirement. As per good practice modularities gives better way to maintain and load application. But answer you can still do.

Collapse
 
mana95 profile image
Manoj Prasanna 🚀

Thank you for the clarification. Yes, I agree—choosing between standalone and modular approaches depends on the specific requirements of the project. While modularity does offer better maintainability and flexibility, it's good to know that the standalone option is still viable and can be applied effectively when needed. Appreciate the insight!