With this daily post, let’s get back to the new Angular standalone features. So far, we have seen how to create standalone components, add dependencies, and lazy-loading of standalone components.
Since the primary goal of standalone components is to have less NgModules
, what about creating an Angular application with no NgModule
at all?
Enter the bootstrapApplication
function (from @angular/platform-browser
). All it needs is the root standalone AppComponent
as a parameter:
And that’s it. No AppModule
needed. Now you’re probably wondering: How to add some router config?
There’s a provideRouter
function for that, along with several router utility functions to configure preloading, guards, error handling, and more:
Last but not least, if you need to use services from a third-party module and don’t want to import the other features of that module (components/pipes/directives), you can also do the following:
As you can see, standalone components have paved the way for many new function-based features (instead of classes/services), and we’ll see even more of those in the coming posts.