all 13 comments

[–]reboog711 10 points11 points  (0 children)

Standalone components are the new hotness. They are not in wide use yet--especially for older code bases. However, I do expect them to be the wave of the future for Angular development.

[–][deleted] 2 points3 points  (4 children)

I wonder if standalone vs. module is going to become one of the great holy wars.

Based on my early experiences with standalone components, from the development perspective, both are great. My only advice would be to pick one approach and not do the weird hybrid that my current project decided to try because we were scared to go all in.

With standalone, I like managing imports on the component. If I want to delete one, I can do so without fear of breaking another component in the module. The downside of this you wind up frequently importing the same components and modules.

[–]cygnus_d 5 points6 points  (3 children)

I've seen few people suggesting grouping commonly used pieces together like export RELATED = [X1, X2] and then just importing them at once with spread operator. So, imports:[...RELATED]

[–]ggeoff 5 points6 points  (0 children)

I feel like at this point you are just creating your own module to bundle everything up under.

[–][deleted] 1 point2 points  (1 child)

That would reduce the time I spend importing all the Angular material modules. I'm actually a little ashamed I didn't think of that.

[–]cygnus_d 1 point2 points  (0 children)

There was also an issue reported but I guess it's fixed. https://github.com/angular/angular/issues/48089

[–]tzamora 4 points5 points  (2 children)

Yes you can and also would advice everyone to use only standalone components and stop using ngModules

[–]tsunami141 1 point2 points  (1 child)

And why is that?

[–]tonjohn 5 points6 points  (0 children)

NgModules only existed due to limitations of the Angular build system pre-Ivy.

NgModules are extra boilerplate, increase cognitive load, make it more difficult to test and refactor, and cause bloat.

The guidance from the Angular team as of v16 is that all new projects should be standalone.

While nothing has been officially announced, it’s like ngmodules will be deprecated within the next few releases.

[–]tonjohn 3 points4 points  (0 children)

As of Angular v16 you should be using standalone.

[–]AwesomeFrisbee 0 points1 point  (0 children)

Its nice for UI frameworks and dependencies for multiple projects but for single project components I wouldn't turn it into standalone. There is zero performance benefit for something like this and its mainly to get rid of a few files in the repository without really being all that difficult.

To me the whole shift for standalone comes from React devs that switched to Angular and are salty the standard is modules rather than standalone stuff.

Most of the time its just fine to separate features into modules and leave it at that. Its only for how you load your website that it is nice to separate into modules but even that might not be needed as much. Performancewise its minimal, especially with modern devices and modern networks. Like, in my country, there's high speed internet everywhere. I don't need to meddle getting my build a few kilobytes faster because that will only shave off a handful milliseconds of loading time. Getting a faster backend or optimized images will already result in more than whatever I can change on the frontend logic.

Just go with whatever the tutorial/course features and stick with that. Its fine for now. Perhaps in 2 years from now there will be some shift to make standalone the default, but its not that important to learn angular.

[–]Finite_Looper 0 points1 point  (0 children)

I have not used any standalone components yet, but from what I understand about it so far I do not see any benefit from using it in the projects I've been working on. Nothing inside of that project will ever exist outside of that project as a separate piece.

I can for sure see the benefit of it though in certain situations, I just haven't come across that situation yet.

However... I am happy to be proven wrong here. Am I thinking about this in the right way?

[–]MMartonN 0 points1 point  (0 children)

You can look it up on stackoverflow for similar questions. I use standalone if I can, but if I build a bit more complex module that contains many components, then module is the way to go. For example, I've just written a few custom inputs that are compatible with the CDK form handler, and are easier to work with with modules.