Angular, the most in-demand, open-source front-end framework, finally drops in yet another version update – Angular 15. Previously, Angular 14 introduced many new exciting experimental features and arrayed code best practices but it seems like this new roll-out Angular version 15, is all about gaining stability.
Finally, a new stable update, which we all tech enthusiasts and the Angular community were waiting for. This new update has brought massive thrilling changes. So, let’s dive into the new world of Angular 15.
In reference to other previous updates and the removal of Angular’s legacy compiler, the Angular 15 update brings many new refinements – stability and extended supportability, that definitely promises to unlock elevated developer experience and performance.
The standalone components API was introduced in Angular 14 to build Angular applications without defining the NgModules. In Angular 15, the standalone components API finally achieves their degree of stability after thorough performance observation and amendments.
NgModules
The Angular developer community has made sure that with this newly achieved stability, standalone components can work in sync with HttpClient, Angular Elements, and many others.
HttpClient
Use this standalone API to bootstrap an application in a single component. Here’s how it is done:
import {bootstrapApplication} from '@angular/platform-browser'; import {ImageGridComponent} from'./image-grid'; @Component({ standalone: true, selector: 'photo-gallery', imports: [ImageGridComponent], template: ` … <image-grid [images]="imageList"></image-grid> `, }) export class PhotoGalleryComponent { // component logic } bootstrapApplication(PhotoGalleryComponent);
Using the imports function, you can even reference standalone directives and pipes.
imports
You can now mark components, directives, and pipes as “standalone: true” – now, no need to declare them into NgModule, else the Angular compiler will throw an error. Additionally, you can now import NgModule directly inside the standalone component by writing import: [module_name].
standalone: true
import: [module_name]
Angular 15 comes with a router standalone API to build the multi-route application. Here’s how you can declare the root route:
export const appRoutes: Routes = [{ path: 'lazy', loadChildren: () => import('./lazy/lazy.routes') .then(routes => routes.lazyRoutes) }];
Here, lazyRoutes are declared in the following way:
import {Routes} from '@angular/router'; import {LazyComponent} from './lazy.component'; export const lazyRoutes: Routes = [{path: '', component: LazyComponent}];
You can register the appRoutes in the bootstrapApplication method and call it using the ProvideRouter API, which is tree-shakable!
appRoutes
bootstrapApplication
ProvideRouter
bootstrapApplication(AppComponent, { providers: [ provideRouter(appRoutes) ] });
Additionally, Angular Bundlers can now remove the unused features at the build time, which can result in an 11% reduction in the code file size.
All developers love when their favorite framework offers top-notch reusability of directives. In the GitHub community, many Angular developers were asking for this API and finally, the team heard it and made it possible.
So, Angular v15 is finally infused with that inspiration from the feature request made on GitHub. It has introduced Directive Composition API, which elevates the code usability and takes it to another level. It allows developers to boost host elements with directives and make the most of Angular with the help of the ultimate code reuse strategy. Additionally, all of this can be made possible with the help of an Angular compiler.
NOTE: You can only make use of the Directive Composition API with standalone directives.
@Component({ selector: 'mat-menu', hostDirectives: [HasColor, { directive: CdkMenu, inputs: ['cdkMenuDisabled: disabled'], outputs: ['cdkMenuClosed: closed'] }] }) class MatMenu {}
As you can see above, the MatMenu is made effective with the help of two hostDirectives: HasColor and CdkMenu.
MatMenu
HasColor
CdkMenu
Because of this enhancement, MatMenu can reutilize all the properties from these two directives. MatMenu can be inherited with the inputs, outputs, and logic associated with the HasColor directive and only logic and input from CdkMenu.
It may give you a feeling like Deja Vu for the multiple inheritance concept. The difference Angular has from other programming languages is the resolution of name conflicts, and it only applies to user interface primitives.
The NgOptimizedImage directive was introduced in the previous version to easily adopt best practices for loading image performance. Finally, after a lengthy observation of developers, this directive has achieved a stable form.The latest experiment done by Land’s End with this feature for one application has observed a 75% improvement in the LCP (Largest Contentful Paint) image loading.
NgOptimizedImage
Previously, this NgOptimizedImage was also offering many features and functionalities, but Angular v15 updates add more new exciting features in the image directive, which are as follows:
srcset
But the question is, “how to use this standalone NgOptimizedImage directive?”
It can be directly used in your Angular component or NgModule.
NgModule
import { NgOptimizedImage } from '@angular/common'; // Include it into the necessary NgModule @NgModule({ imports: [NgOptimizedImage], }) class AppModule {} // ... or a standalone Component @Component({ standalone: true imports: [NgOptimizedImage], }) class MyStandaloneComponent {}
When using this Angular image directive within a component, all you need to do is replace the image src attribute with ngSrc, while ensuring to specify the priority attribute to optimize the speed for the LCP images.
src
ngSrc
Let’s understand this concept in a better way with one example of defining guards, verifying details – whether the user has logged in or not:
@Injectable({ providedIn: 'root' }) export class MyGuardWithDependency implements CanActivate { constructor(private loginService: LoginService) {} canActivate() { return this.loginService.isLoggedIn(); } } const route = { path: 'somePath', canActivate: [MyGuardWithDependency] };
Here, in this program, LoginService contains the main logic, wherein the guard – only one trigger is invoked, which is isLoggedIn (). Although having such a clear structure, this code segment has many boilerplates, which must be reduced.
LoginService
isLoggedIn ()
Thanks to Functional Router Guards, this code can be refactored into the given-below code with the necessary boilerplates.
const route = { path: 'admin', canActivate: [() => inject(LoginService).isLoggedIn()] };
The best thing about Functional Guards is that they are compostable. With its help, you can build factor-like functions, accepting a given configuration and returning a guard or function that resolves a matter.
With the Angular v15 update, debugging Angular applications has been simplified and made cleaner and straightforward with stack traces. The Angular developers’ team ensured to achieve a standard to trace more of a development code than showing libraries it calls. This achievement has made it possible for the error messages to use some improvements.
Before working with the previous Angular versions, when discovering a code, developers used to get one-liner error messages, leading them to a lengthy process to solve that bug.
Below is the snippet for previous error indications:
ERROR Error: Uncaught (in promise): Error Error at app.component.ts:18:11 at Generator.next (<anonymous>) at asyncGeneratorStep (asyncToGenerator.js:3:1) at _next (asyncToGenerator.js:25:1) at _ZoneDelegate.invoke (zone.js:372:26) at Object.onInvoke (core.mjs:26378:33) at _ZoneDelegate.invoke (zone.js:371:52) at Zone.run (zone.js:134:43) at zone.js:1275:36 at _ZoneDelegate.invokeTask (zone.js:406:31) at resolvePromise (zone.js:1211:31) at zone.js:1118:17 at zone.js:1134:33
The difficulty in understanding these ERROR snippets was:
After a long collaboration with the Angular and Chrome DevTool team, the community was able to integrate those third-party dependencies (with the help of node_modules, zone.js, etc.); and thus, could achieve linked stack traces.
The improvement in the stack traces are mentioned below:
ERROR Error: Uncaught (in promise): Error Error at app.component.ts:18:11 at fetch (async) at (anonymous) (app.component.ts:4) at request (app.component.ts:4) at (anonymous) (app.component.ts:17) at submit (app.component.ts:15) at AppComponent_click_3_listener (app.component.html:4)
Now, these error messages provide information from where the error has been encountered, so developers can directly go to that code part and fix it immediately.
As the stability is concerned for the Angular materials, the Angular developer team worked hard to refactor its component based on the Angular Material Design Components for the web applications. Furthermore, these components are enhanced to offer better accessibility and abidance to the Angular Material Design Specifications.
Here, most of the refactoring work has been done in the DOM and CSS parts. Following the new update on responsiveness, there will be some styles in the old Angular applications that need adjustments, especially in the case of CSS overriding internal elements of the migrated components.
In the latest Angular v15, many components’ old implementations have been deprecated. So, to recover them, developers still have the option to go for the “legacy” import.
For instance, you can retrieve the old mat-button implementation by importing its legacy button module.
mat-button
import {MatLegacyButtonModule} from '@angular/material/legacy-button';
CDK stands for Component Dev Kit that offers different behavior primitives, helping in building UI components. In the Angular v15, it gets a new primitive called CDK Listbox, enabling developers to customize Listbox interactions drawn up by the WAI-ARIA Listbox pattern based on requirements.
Here, the behavioral interactions include keyboard interactions, bidi layout support, and focus management. No matter which one of them you use, each directive comes up with associated ARIA roles with respective host elements.
In the Angular 14 update, there was enablement to an experimental support esbuild – a faster javascript bundler, enabling quick build done with simplifying the pipeline.
The Angular 15 comes up with new experimental support for the ng build --watch support, Sass, SVG template, and file replacement. The command for upgrading the angular.json builder is:
ng build --watch
angular.json
"builder": "@angular-devkit/build-angular:browser-esbuild"
Below is the list of new enhancements and enablements made in the Angular 15, which may look small but have a heavy impact.
It is all about the new amendments and achievements enabled in the Angular v15, but the question is, “How will you unlock these Angular 15 capabilities?”
Before upgrading to Angular v15, you must know the support extension, cancellation, and deprecations – breaking changes, to review and refactor your existing Angular build.
ng update @angular/core@15 @angular/cli@15
@keyframes host-my-cmp_foo { ... }
enableIvy
canParse
analyze
hint
RouterOutlet
DATE_PIPE_DEFAULT_TIMEZONE
DATE_PIPE_DEFAULT_OPTIONS
routerLinkWithHref
RouterLink
href
Well, there are other methods and directives that have been removed and updated with a new simplified syntax structure. So, it’s better to go with the Angular v14 to v15 migration guide to ensure a smoother application migration.
Use the following command to update Angular 14 to Angular 15:
ng update @angular/cli @angular/core
Write up the below-mentioned command in CLI to update your global Angular:
npm i -g @angular/cli
The decision for launching Ivy in 2020 was the best one as it has enabled a lot of improvements – NgModules was one of them. This improvement is helping to make the learning curve easier and more simplified.
The team Angular is working on making more improvements to the server-side rendering pipeline, and enhancement in the code reusability is next in line to make Angular more effective.
So, let’s upgrade to Angular v15 and wait for the new exciting update to get acquainted with.
Vijay Sadhu is a Team Lead at MindInventory with 7+ years of experience in frontend architecture and development. He specializes in modern technologies such as React.js (Next.js), Vue.js (Nuxt.js), Angular, Redux, GraphQL, and Node.js. Vijay also has experience with AWS, Firebase, Three.js, AI integrations, and building AI-driven web applications.
First Name
Last Name
Email
CountryIndiaAfghanistanAland IslandsAlbaniaAlgeriaAmerican SamoaAndorraAngolaAnguillaAntarcticaAntigua and BarbudaArgentinaArmeniaArubaAustraliaAustriaAzerbaijanBahamasBahrainBangladeshBarbadosBelarusBelgiumBelizeBeninBermudaBhutanBoliviaBonaire, Sint Eustatius and SabaBosnia and HerzegovinaBotswanaBouvet IslandBrazilBritish Indian Ocean TerritoryBrunei DarussalamBulgariaBurkina FasoBurundiCambodiaCameroonCanadaCape VerdeCayman IslandsCentral African RepublicChadChileChinaChristmas IslandCocos (Keeling) IslandsColombiaComorosCongoCongo, Democratic Republic of the CongoCook IslandsCosta RicaCote D'IvoireCroatiaCubaCuracaoCyprusCzech RepublicDenmarkDjiboutiDominicaDominican RepublicEcuadorEgyptEl SalvadorEquatorial GuineaEritreaEstoniaEthiopiaFalkland Islands (Malvinas)Faroe IslandsFijiFinlandFranceFrench GuianaFrench PolynesiaFrench Southern TerritoriesGabonGambiaGeorgiaGermanyGhanaGibraltarGreeceGreenlandGrenadaGuadeloupeGuamGuatemalaGuernseyGuineaGuinea-BissauGuyanaHaitiHeard Island and McDonald IslandsHoly See (Vatican City State)HondurasHong KongHungaryIcelandIndonesiaIran, Islamic Republic ofIraqIrelandIsle of ManIsraelItalyJamaicaJapanJerseyJordanKazakhstanKenyaKiribatiKorea, Democratic People's Republic ofKorea, Republic ofKosovoKuwaitKyrgyzstanLao People's Democratic RepublicLatviaLebanonLesothoLiberiaLibyan Arab JamahiriyaLiechtensteinLithuaniaLuxembourgMacaoMacedonia, the Former Yugoslav Republic ofMadagascarMalawiMalaysiaMaldivesMaliMaltaMarshall IslandsMartiniqueMauritaniaMauritiusMayotteMexicoMicronesia, Federated States ofMoldova, Republic ofMonacoMongoliaMontenegroMontserratMoroccoMozambiqueMyanmarNamibiaNauruNepalNetherlandsNetherlands AntillesNew CaledoniaNew ZealandNicaraguaNigerNigeriaNiueNorfolk IslandNorthern Mariana IslandsNorwayOmanPakistanPalauPalestinian Territory, OccupiedPanamaPapua New GuineaParaguayPeruPhilippinesPitcairnPolandPortugalPuerto RicoQatarReunionRomaniaRussian FederationRwandaSaint BarthelemySaint HelenaSaint Kitts and NevisSaint LuciaSaint MartinSaint Pierre and MiquelonSaint Vincent and the GrenadinesSamoaSan MarinoSao Tome and PrincipeSaudi ArabiaSenegalSerbiaSerbia and MontenegroSeychellesSierra LeoneSingaporeSt MartinSlovakiaSloveniaSolomon IslandsSomaliaSouth AfricaSouth Georgia and the South Sandwich IslandsSouth SudanSpainSri LankaSudanSurinameSvalbard and Jan MayenSwazilandSwedenSwitzerlandSyrian Arab RepublicTaiwan, Province of ChinaTajikistanTanzania, United Republic ofThailandTimor-LesteTogoTokelauTongaTrinidad and TobagoTunisiaTurkeyTurkmenistanTurks and Caicos IslandsTuvaluUgandaUkraineUnited Arab EmiratesUnited KingdomUnited StatesUnited States Minor Outlying IslandsUruguayUzbekistanVanuatuVenezuelaViet NamVirgin Islands, BritishVirgin Islands, U.s.Wallis and FutunaWestern SaharaYemenZambiaZimbabwe
Country Code+91+93+358+355+213+1684+376+244+1264+672+1268+54+374+297+61+43+994+1242+973+880+1246+375+32+501+229+1441+975+591+599+387+267+55+55+246+673+359+226+257+855+237+1+238+1345+236+235+56+86+61+672+57+269+242+242+682+506+225+385+53+599+357+420+45+253+1767+1809+593+20+503+240+291+372+251+500+298+679+358+33+594+689+262+241+220+995+49+233+350+30+299+1473+590+1671+502+44+224+245+592+509+0+39+504+852+36+354+62+98+964+353+44+972+39+1876+81+44+962+7+254+686+850+82+383+965+996+856+371+961+266+231+218+423+370+352+853+389+261+265+60+960+223+356+692+596+222+230+262+52+691+373+377+976+382+1664+212+258+95+264+674+977+31+599+687+64+505+227+234+683+672+1670+47+968+92+680+970+507+675+595+51+63+64+48+351+1787+974+262+40+7+250+590+290+1869+1758+590+508+1784+684+378+239+966+221+381+381+248+232+65+721+421+386+677+252+27+500+211+34+94+249+597+47+268+46+41+963+886+992+255+66+670+228+690+676+1868+216+90+7370+1649+688+256+380+971+44+1+1+598+998+678+58+84+1284+1340+681+212+967+260+263
Contact Number
Message
Get a free access of our exclusive research and tech strategies to level up your knowledge about the digital realm.