Latest Features of Angular - Js - DZone Web Dev
Latest Features of Angular - Js - DZone Web Dev
• Learn about all the features of Corvid by Wix and find out how you can begin quickly building advanced
web applications.
Presented by Wix
The latest version of Angular was slated to release in March April 2019 But it
The latest version of Angular was slated to release in March-April 2019. But, it
eventually happened in 2019. Yes, we are talking about Angular 8 — the latest
version of Angular.js.
However, Angular 7.0 is supported until April 2022. So, it becomes imperative for
organizations to explore the new features incorporated in Angular 8 and decide
on embracing Angular 8 whether or not they should upgrade from Angular 7.0.
In the latest version, Angular serves different browsers with different bundles,
and this is by default. The CLI extensions generate different bundles for old legacy
(ES5) browsers and modern JavaScript (ES2015+) browsers.
Moreover, it enhances the loading speed and the time to interactive (TTI) for a
modern browser. The speed of applications and building a process takes place by
using polyfills or modern syntax. Moreover, differential loading also helps in
saving 7 to 20 percent of bundle size on average.
Differential loading in Angular 8.0 forms a part of Manfred Steyer's project, ngx-
build-modern. All bundling is done with the ng build command and
the -prod extension, without requiring special actions.
You may also like: Angular: Everything You Need to Know [Tutorials].
Angular emphasizes consent on data sharing, unlike other platforms that collect
d t b d f lt t t b i It t h d th tt
data by default on an opt-out basis. It stops when you command them not to.
Others don’t even allow them to ask them to share telemetry.
The code running in the web worker cannot exist in the same JavaScript file in the
application. These two must be different. Those working with tools such as
Angular CLI bundles JavaScript automatically into a as few files as possible.
With the new improvements, Angular 8.0 makes it possible to fully parallelized
web worker bundling. It acts as a relief for front-end developers who face
limitations in single-thread.
You can run the following if you want to create a new CLI with a web worker.
FORMS
MarkAllAsTouched
MarkAllAsTouched is a method in Angular 8 used in the AbstractControl class.
The method touches marks control and descendants as touched as shown below:
1 form.markAllAsTouched();
FormArray.clear
In Angular 8, the FormArray class offers a clear method, which quickly removes
all control it contains. You no longer have to loop over every control one-by-one,
as shown below:
ROUTER
Location
To migrate to Angular 8, you should be aware of a few things added to the location
services:
Service Worker
A service worker in Angular is a script that runs in a web browser and manages
cache for an application. It augments the traditional web deployment model and
empowers the application to deliver a reliable user experience with performance
on par with natively-installed code.
Registration Strategy
In previous versions, the Service worker was waiting for a stable application to
register. This was used to avoid slowing the start of an application. The new
option has an option that specifies when the registration will take place.
But, with Angular 8, this is possible with the option of registrationStrategy for
handling the registration for a service worker with the following values:
TypeScript 3.4
It is now mandatory for Angular 8 to use TypeScript 3.4. The development team
must upgrade the TypeScript. It helps when using readable and clean JavaScript
code. TypeScript 3.4 introduces a new flag named incremental. It saves
information from the project graph from the last compilation. While using
Incremental, the information detects the least costly way to emit changes for your
project and type-check.
It uses third-party tools and libraries to assist you in processes such as building
and deployment. Moreover, Angular leverages Cloud for APIs. AngularFire is the
official library that connects Angular with Firebase. AngularFire adds the deploy
command to simplify the process of deployment and build by Firebase with the
following:
1 ng add @angular/fire
2 ng run my-app:deploy
AngularJS Migration
Angular 8 enables the users of $location services, as it now allows a Location
Upgrade Module in the AngularJS applications. It helps to translate the unified
location service and shifts the responsibility from AngularJS $location to the
Angular Location. It eases our applications with hybrid operations and depends
on the upgrade along with route in AngularJS and part.
Bazel
The latest Angular version makes it easier to build CLI applications. All this is due
to Bazel, developed by Google. It is a build tool that works well with any language
inputs. Some benefits of Bazel are:
About IVY
Ivy is the prime feature of Angular 8 and included as an opt-in preview for
testing. Ivy is a new compiler to build next-gen rendering pipelines in the current
version. It increases the efficiency of the latest version. It helps to improve
runtime speed with simplified incremental compiling with its ability to generate
bundles of significantly smaller size.
Moreover, it uses the concept of incremental DOM, where each component gets
compiled with a set of instructions that constitutes the DOM tree. It updates it
with a change in data.
Developers can use Ivy to determine the potential and performance of Angular
applications. It never alters any of the existing applications. On completion, it will
make the Angular applications smaller, simpler, and faster.
Advantages of IVY
The advantages of Ivy are:
Smaller Bundles.
Reduced Payload Size.
Faster Rebuild times.
Enhance Backwards Compatibility .
Pre-compiled Code shipment .
Dismissal of metadata.json.
Rise of meta programming.
Improve template type checking.
Broad Compatibility with existing Angular applications.
Notable Changes
The angular team makes your life easier with Schematics. Schematic updates your
code by simply running:
1 ng update @angular/cor
Query Timing
The decorators, ViewChild and ContentChild , now have a new option called
static. If the queried element is static (not wrapped in ngIf and ngFor . Thenm, it
is available in ngOnInit :
So,
1 <h1 #staticDiv>static</h1>
2
3 Gives
4
5 @ViewChild('staticDiv') staticDiv: ElementRef<HTMLDivElement>;
6
7 ngOnInit() {
8 console.log('init static', this.staticDiv); // div
9}
9}
0
1 ngAfterViewInit() {
2 console.log('after view init static', this.staticDiv); // div
3}
A static flag, when introduced, not only breaks existing applications, but you can
use the following to keep the old behavior, even when switching to Ivy. It ensures
the same behavior as the current one.
1 <button
2 *ngFor="let option of options"
3 (click)="option = 'newButtonText'">{{ option }}</button>
However, this is no longer possible in Ivy. It does not allow us to assign a value to
a template variable like an option in the above example.
When you upgrade to Angular 8 to prepare for the switch to Ivy, a schematic
analyzes the template and issues a warning for such a case.
1 <button
2 *ngFor="let option of options; index as index"
3 (click)="options[index] = 'newButtonText'">{{ option }}</button>
Document
The token DOCUMENT gets moved from the @angular/platform-browser to
@angular/common . It is manually possible to change it with a schematic provided
for the purpose.
You can find the list of all deprecated API packages obtained here.
Conclusion
Other than Ivy, the additions to Angular 8 are not that critical or significant. You
can gather insights on the Ivy preview from the official Ivy guide provided.
However, it is recommended to upgrade to Angular 8 to ensure that your apps are
all ready for Ivy.
Moreover, Ivy will become the default in the next version of Angular, so now it
the best option for you to check whether your apps are going to need any
changes.
Further Reading
Angular 7 + Spring Boot Application: Hello World Example
Angular 7 + Spring Boot Application: Hello World Example.
Top 10 Angular Tutorials and Courses for Web Developers.
Developing a Web Application Using Angular (Part 1).
Topics: WEB DEV , ANGULAR , JAVASCRIPT , FRONTEND FRAMEWORK , ECMA , ES6 , NODE , NPM , NG