1. Angular 14: New Features and Updates
Sreelekha C P | Sep 13 2022
Angular, a typescript-based web application framework is Google’s one advanced and brilliant
creation. Google has released its latest version which is Angular 14. Here we’re going to describe
what Angular 14 has brought for Angular developers in terms of updates and features. Angular 14
version was released and like every new version, it of course also introduces a couple of simple
changes and minor new features and improvements. Version 14 introduces several features. Typed
Forms and Standalone Components. In this article, we’ll take a look at these two big new features.
2. Angular 14 – Key Highlights of Angular
Angular 14 is at last here after the progress of its predecessor Angular 13. The Type-script-based
web application system is the next significant Google release. Angular 14 has shown up with
stand-alone components, promising to streamline Angular app development by diminishing the
requirement for Angular modules. The upgrade from Angular 13 to Angular 14 induces advanced
opportunities for typed forms, improved template diagnosis, and stand-alone components. Angular
14 is accepted to be the most systematic pre-planned upgrade by Angular. The Angular 14 delivery
new highlights CLI auto-completion, typed reactive forms, stand-alone components, directives and
pipes, and enhanced template diagnostics. The highlight of this update is that the Angular experts
have carefully seasoned out the need for Ng modules, reducing the amount of boilerplate code
required to start the application. Before discussing the Angular14 features, let us contrast Angular13
with the new Angular14 updates.
3. Typed Forms: Angular 14
Angular 14 was designed with one deal in mind: to provide forms more user-friendly. Here I’ve got a
standard form using the Reactive Forms approach which is offered by Angular. In angular, you can
handle forms with the Template-driven approach or by using the Reactive approach we are using
Reactive approach here because Typed Forms only apply to Reactive Forms, not to Template-driven
forms. There is no change to Template-driven forms.
Now, here for Reactive Forms though, the HTML code is the same as you would have been for
Angular 13,12,11, and so on. So this code does not change as follows
Email
Age
Submit
If you have a look at the Typescript code, for this component, the code also doesn’t change that
much.
export class AppComponent{
4. form=new FormGroup({
email:new FormControl(null),
age:new FormControl(null)
});
}
Here, I am creating a Form Group with an email and an age Form Control and I’m connecting this
FormGroup and then the individual controls to my HTML elements. However, we’ll see a difference if
we then try to work with our FormGroup here in the typescript code. For example, upon form
submission, we might want to log or send the individual form-controlled values to a server or the
console here in this case. Here are two controls in that FormGroup and they are both null initially but
I’m not passing any other information to typescript. TypeScript infers that they are always null so that
there can never be any other value inside of such a FormControl besides null.
FormControl is now a generic type where we can specify which values can end up in that
FormControl. Here we could say that it’s a string or null as follows, form=new FormGroup({ email:
new FormControl(null),
age:new FormControl(null)
});
For email, we could say that it’s maybe a string/null that would be possible here and for age, we
could say that it’s maybe a number/null. [Idea behind Typed forms is simply that you have more type
safety in its code, that we’re not operating on any as much because the problem with type any is that
all code looks fine whilst you’re writing it but our app could crash in certain scenarios at runtime.]
Standalone Components
It is one of the most amazing features added to Angular in a Long Time because
it has the potential of making writing Angular apps much simpler and easier
than today. The idea behind standalone components is that you can get rid of
modules.
@NgModule({
Declarations:[
AppComponent
],
Imports:[
BrowserModule,
5. ReactiveFormsModule
],
Provider:[],
Bootstrap:[AppComponent]
})
Export class AppModule{ }
Now let’s see how to migrate the app component to be a standalone component without requiring
NgModule.To make this work, we have to add a new flag to the @Component decorator
configuration here, the standalone flag, and we have to set this to true. After adding this flag here,
we have to add all the imports and providers that are required by that component to this component.
This component doesn’t need any providers but it needs some imports. So there are no declarations
array which we add here, as we have it in NgModule. If this component used other components, they
would also be added to imports here. After this, you can get rid of this AppModule. @Component({
standalone:true, imports:[ReactiveFormsModule], selector:’app-root’,
Now since this was the AppModule our root module for the root component, we also have to
bootstrap the application differently.
Instead of bootstrapping it like this,
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err=>console.error(err));
We bootstrap by calling bootstrap application, which is imported from
@angular/platform-browser,
Bootstrap Application (App Component);
Bootstrap Application is a function that is called and to this function, we now pass the root
component of our application, in this case, the App Component which also has to be imported from
the App Component file. This is how our application if our root component is a Standalone
Component.
Streamlined Page Title Accessibility
6. While developing Angular apps your page title distinctively represents the content of your page. In
the previous release of Angular 13, the most common way of adding titles was streamlined with the
new advanced Route. Title property in the Angular Router. Presently with Angular 14, there are no
more extra imports required when adding a title to your page.
Extended Developer Diagnostics:
The extended developer diagnostics is an Angular14 feature conveying an extendable structure that
helps better understand your template and shows suggestions facilitating potential boosts.
New primitives in the Angular CDK
The Component Dev Kit (CDK) from Angular provides a comprehensive set of tools for making
Angular components. The CDK Menu and Dialog have now been elevated to a stable version in
Angular 14! The expansion of new CDK primitives in Angular 14 considers the production of more
accessible custom components.
Advanced Angular DevTools is Available Offline and in
Firefox
The professional Angular DevTools debugging extension has recently enabled offline support, all
credit goes to a community contribution by Keith Li. For advanced Firefox users, create the
extension in the Add-ons for Mozilla.
So, here we have reached by getting along with the advanced features of Angular 14, you should be
looking forward to employing this in your development process. We shall head to this stop again
when Google shocks us with yet another version of the Angular release. Typed Forms and
Standalone components are the two most exciting features of Angular 14. Typed Forms/Typed
Reactive forms can help us make our code safer and catch errors earlier. Now, Standalone
components are not fully there yet. it’s in preview and features might still change in certain aspects
however this feature has the potential of making Angular way more professional and allowing us to
build way leaner advanced Angular apps in the future.