
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...
For further actions, you may consider blocking this person and/or reporting abuse
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 🤔
I used vscode. Didn’t show any error. I tried multiple triage then landed to solution.
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.
Do you have any example for reference to look ?
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...
Thanks for references.
Tried this and its works fine.
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...
Sure I will try for this. is require to upgrade Angular version for this ?
You need at least Angular 17 for this
I am using 18 will surely give it try. Thanks
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.
Updated blog with latest changes. Thanks for recommendation.
When developing an application, is it acceptable to build it without a standalone mode? What are your thoughts on this?
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.
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!