09 Sep 2019
3 min

What’s new After Angular 8

In this blog post let’s see what is going on with Angular 8 post the official release in May 2019.

Introduction

We got many new features with the release of Angular 8, Angular 9 will be released around November 2019. There are a lot of interesting things happening after Angular 8 was released in May, we have Ivy as default, ng deploy is officially support by CLI and many more.

New Features

Capture Location Updates from AngularJS Application

A new hook onChange is added, this hook can be used to capture changes to browser URL done by AngularJS application. Below is the code snippet from spec file, you can pass changeListener and errorHandler function

$location.onChange(changeListener, errorHandler);
function changeListener(url: string, state: unknown) 
{ 
      return undefined; 
} 
function errorHandler(e: Error) {}

Unit Test Helpers

2 new Unit Test Helpers are added so we can Unit Test Angular Service while upgrading AngularJS project.

Typescript

Typescript 3.5.x is required with 8.2.0 release.

Migration from Renderer to Renderer2

Renderer was deprecated long back and new Renderer2 was introduced, now ng update will automatically migrate the code to Renderer2.

Support $element in the upgraded component

An upgraded component that uses a template function doesn’t receive the $element or $attrs arguments earlier, now it will receive $element.

Deprecations

Platform WebWorker

Platform web worker packages @angular/platform-webworker and @angular/platform-webworker-dynamic are officially deprecated, the Angular team realized it's not good practice to run the Angular application on Web worker due to poor API and tooling support. If you are interested in learning more about it you can read the entire message on Commit

Web Tracing Framework

Angular supported the integration with the Web Tracing Framework (WTF) for performance testing. As it is not maintained and fails for the majority of applications, this is deprecated now.

Breaking Changes

Slice Pipe

The SlicePipe used to take vale of type any earlier, SlicePipe now only accepts an array of values, a string, null or undefined. It will throw a compilation error if any other data type is used.

Angular CLI

  • The Angular root component in the default app is redesigned to include few commands on UI.
  • ng deploy command is added for supporting the deployment builders created by the community.
  • While creating a new module you can also define if you need the module to be lazy-loaded. The below command generates the ProductModule and will add the routing configuration in app-routing.module to lazy load the ProductModule
ng g module product --routing true --route product --module app
  • In Angular, 8 differential loading feature was added, and compiler used to build the application twice once for ES2015 and another with ES5 which caused a lot of confusion for the developers, as we have seen many questions over StackOverflow and on GitHub as well. With latest CLI release you will not notice this behavior anymore. With CIL 8.3.0 only the ES2015 application is built and then the resulting application bundles are then down leveled directly.

Conclusion

The Angular 9.next is already available and Ivy is now the default rendering engine and in a few months we will have RC version and it will be clear what more we can expect from Angular. There are a lot of performance improvements and bug fixes which is happening in parallel.

Frequently asked questions

What does the ng deploy command do in Angular CLI 8?

The ng deploy command runs deployment builders created by the community to support deploying an Angular application. It was added to the Angular CLI after Angular 8, but the article does not describe a built-in deployment provider or a particular hosting platform. The command’s behavior depends on the deployment builder used by the project.

How did differential loading change in Angular CLI 8.3?

Angular CLI 8.3 builds the ES2015 application once and then downlevels the resulting bundles, instead of building the application separately for ES2015 and ES5. This change addressed confusion caused by the earlier two-build process. The article describes this behavior specifically for CLI 8.3.0.

Does ng update migrate Renderer to Renderer2 in Angular?

Yes, ng update automatically migrates code from the deprecated Renderer API to Renderer2. Renderer2 had already been introduced as its replacement, and the migration support removes the need to make that change manually for the code handled by the update.

What types can Angular's SlicePipe accept after Angular 8?

Angular’s SlicePipe accepts an array, a string, null, or undefined; using another data type causes a compilation error. This is a breaking change from its earlier any input type, so check values passed to the pipe during an upgrade.

How can I capture AngularJS URL changes in an Angular upgrade project?

Use $location.onChange(changeListener, errorHandler) to capture browser URL changes made by an AngularJS application. The change listener receives the URL and state, while the error handler receives an Error. This hook is intended for AngularJS applications involved in an Angular upgrade.

Which Angular packages were deprecated after Angular 8?

The @angular/platform-webworker and @angular/platform-webworker-dynamic packages were deprecated because of poor API and tooling support for running Angular applications in web workers. Angular also deprecated its Web Tracing Framework integration because the framework was unmaintained and failed for most applications.

Share this post

Sign up for our newsletter

Stay up-to-date with the trends and be a part of a thriving community.