Home Web Development Accelerating Angular Development with Ivy

Accelerating Angular Development with Ivy

By Lars Gyrup Brink Nielsen , Mateus Carniatto , Jacob Andresen
books-svg-icon Book
eBook $25.99 $17.99
Print $32.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $25.99 $17.99
Print $32.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Chapter 2: Boosting Developer Productivity Through Tooling, Configuration, and Convenience
About this book
Angular Ivy is the latest rendering engine and compiler introduced in Angular. Ivy helps frontend developers to make their Angular applications faster, better optimized, and more robust. This easy-to-follow guide will help you get to grips with the new features of Angular Ivy and show you how to migrate your Angular apps from View Engine to Ivy. You'll begin by learning about the most popular features of Angular Ivy with the help of simple stand-alone examples and realize its capabilities by working on a real-world application project. You'll then discover strategies to improve your developer workflow through new debugging APIs, testing APIs, and configurations that support higher code quality and productive development features. Throughout the book, you'll explore essential components of Angular, such as Angular Component Dev Kit (CDK), Ahead-of-time (AOT) compilation, and Angular command line interface (CLI). Finally, you'll gain a clear understanding of these components along with Angular Ivy which will help you update your Angular applications with modern features. By the end of this Angular Ivy book, you will learn about the core features of Angular Ivy, discover how to migrate your Angular View Engine application, and find out how to set up a high-quality Angular Ivy project.
Publication date:
October 2021
Publisher
Packt
Pages
242
ISBN
9781800205215

 

Chapter 1: Discovering New APIs and Language Syntax

As its only officially supported programming language, Angular is tightly coupled with TypeScript. Support for new versions of TypeScript is introduced with major and minor version releases of Angular. In this chapter, we will explore three powerful language features that have been released in the recent versions of TypeScript and Angular:

  • The optional chaining operator (?.)
  • The nullish coalescing operator (??)
  • Native private class members (#)

Through simple examples, we will highlight the strengths of these modern programming language features. We will even learn how two of the new operators work elegantly together in common scenarios. Learning about this new syntax and semantics is key to understanding the examples throughout this book.

Globalization is the process of supporting and adapting multilingual and regional capabilities in an application. Angular Ivy introduces improved globalization APIs. Together...

 

Technical requirements

To support all the features introduced in this chapter, your application requires at least the following:

  • Angular Ivy version 9.1
  • TypeScript version 3.8

You can find the complete code examples for the globalization APIs in this book's companion GitHub repository at https://github.com/PacktPublishing/Accelerating-Angular-Development-with-Ivy/tree/main/projects/chapter1/globalization.

 

Modernizing your code with powerful language features

TypeScript is an integral part of Angular, but because Angular has its own compiler transformations that extend TypeScript's compilation steps, we are inevitably tied to the version of TypeScript that the Angular compiler supports. Fortunately, Angular is good at keeping up with recent versions of TypeScript. In this section, we are going to discuss some of the most noteworthy additions to the TypeScript language in the most recent versions supported by Angular Ivy.

The optional chaining operator

TypeScript version 3.7 introduces a new operator for optional property access, optional element access, and optional calls. The optional chaining operator (?.) short circuits in the case of nullish values – that is, null or undefined – in which case it evaluates to undefined.

Optional chaining is great for working with composite objects or just plain old complex data structures such as large business documents...

 

Optimizing regional support with improved globalization APIs

Multilingual applications use globalization to give users from different countries and backgrounds a regional experience. Angular has built-in APIs for managing both internationalization and localization. In this section, we will walk through configuration and implementation examples to illustrate some of the new globalization possibilities Ivy brings us.

Bundling localizations

Angular uses locale data for regional variations for formatting dates, currencies, decimal numbers, and percentages. In Angular Ivy, we can bundle a single locale as part of the build by using the localize builder option. Let's say we wanted our application to use the French locale. We can do this by configuring our project build as follows. This also implicitly replaces the value provided for the LOCALE_ID dependency injection token in the @angular/core package:

{
  "projects": {
    "my-app...
 

Enhancing tests with stronger types and new APIs

For many different types of tests, Angular's TestBed API is both necessary and useful. Ivy introduces a strongly typed API for resolving dependencies through the Angular testing module injector, which can be configured using the static TestBed.configureTestingModule method. In this section, we will explore stronger typing in Angular tests.

Let's also look at an integrated component test for an Angular component using a custom Angular Material SVG icon. This can be done using the FakeMatIconRegistry service that was introduced with Angular Ivy.

Resolving strongly typed dependencies with TestBed.inject

TestBed.get always returns a value of the any type. This static deprecated method has not been deprecated as of Angular version 12, but it could be removed in any major version following that. Its replacement is the type-safe TestBed.inject static method.

Let's look at a couple of simple examples to see the immediate...

 

Summary

In this first chapter, we discussed the modern language features that were introduced with the recent versions of TypeScript to accompany Angular Ivy. Through simple, common examples, we learned about nullish coalescing and optional chaining. We also identified the differences between TypeScript access modifiers and native private class members, all of which are features that we will make use of throughout the code in this book. By learning about these topics, you can now refactor your existing application or implement new features using these powerful language additions.

Globalization is needed for regional and multilingual support in Angular applications. We covered the basics of configuring multiple locales for our Angular build process. After that, we discovered our newfound ability to lazy load locale data such as regional number, currency, and date formats, as well as directionality information.

To demonstrate runtime locale switching, we created a locale picker...

About the Authors
  • Lars Gyrup Brink Nielsen

    Lars Gyrup Brink Nielsen is a Co-Founder of an Open Learning non-profit called This is Learning. He's a Tech Writer at This is Angular. Lars speaks at meetups, conferences, and live streams worldwide. He's a FOSS maintainer and Open Learning contributor. Lars is also a Microsoft MVP in Developer Technologies and a GitHub Star. As a Frontend Architect at Systematic A/S, he architects and delivers cloud-native solutions for the Danish energy industry using Continuous Delivery and automation with modern tech stacks and toolchains built for scale.

    Browse publications by this author
  • Mateus Carniatto

    Contacted by Royluis on 29th Jan20

    Browse publications by this author
  • Jacob Andresen

    Jacob Andresen works as a senior software developer based in Copenhagen in Denmark. He has been working as a software developer and consultant in information retrieval systems and web applications since 2002.

    Browse publications by this author
Accelerating Angular Development with Ivy
Unlock this book and the full library FREE for 7 days
Start now