The improvements of Angular 9.0.0

The improvements of Angular 9.0.0

Angular 9.0 is still in RC (RC6) as of now. But with all the improvements we’ve gone over here, Angular 9.0 will be a welcome update that should help every developer be successful. Well given that most apps currently are built with Angular and Ionic. For reference, we’ll be looking at the Angular version of the Star Track demo app – built with Ionic 4 and Angular – and checking out the improvements. Note that Star Track is using almost every feature available from Angular, so delta is a bit smaller, but still a welcomed improvement! Now Ivy has been around for sometime in earlier release, but always as an opt-in feature. With 9.0, however, Ivy is enabled by default and developers need to opt-out manually.

One of the biggest updates in the pipeline right now is the upcoming release of Angular 9.0.0. Currently in RC, Angular 9.0 will hopefully ship early next year. But this release includes so much that I thought it required a post to highlight some of the most important updates. Now for Ionic devs, why should they care about this? Well given that most apps currently are built with Angular and Ionic, any improvements to the overall ecosystem should always be welcomed! But given the goals of Angular 9.0, this directly impacts (in a positive way) Ionic be being able to ship faster and smaller apps, in faster manner. For reference, we’ll be looking at the Angular version of the Star Track demo app – built with Ionic 4 and Angular – and checking out the improvements.

Ivy By Default

One of the biggest improvements to Angular coming in 9.0 is that Ivy is enabled by default. Ivy is Angular’s new renderer. A super high level overview is that Ivy enables apps to only require pieces of the render that they actually need, instead of the whole thing. This means that our final output will be smaller, which is always better for performance. It’s important to note, that Ivy won’t make your components/app significantly smaller if you’re using every feature available to Angular. But there are noticeable improvements to the main.js chunk of an app.

For comparison, let’s look at the build output from Star Track with Ivy enabled and with it disabled. We’ll compare the size of the main.js file, which is mostly going to be Angular specific code.

# Ivy disabled
$ ng build --prod
...
chunk {10} main-es2015.d03d9cadf1579320f520.js (main) 537 kB [initial] [rendered]
chunk {10} main-es5.d03d9cadf1579320f520.js (main) 628 kB [initial] [rendered]
...

# Ivy enabled
$ ng build --prod
...
chunk {10} main-es2015.bfc9e260b847bc2b02fc.js (main) 465 kB [initial] [rendered]
chunk {10} main-es5.bfc9e260b847bc2b02fc.js (main) 551 kB [initial] [rendered]
..

From 537kb/628kb without Ivy, to 465kb/551kb with it! Note that Star Track is using almost every feature available from Angular, so delta is a bit smaller, but still a welcomed improvement!

Now Ivy has been around for sometime in earlier release, but always as an opt-in feature. With 9.0, however, Ivy is enabled by default and developers need to opt-out manually. If Ivy is so great, why would developers need to opt-out of it? Well, as this is part of a new major version, there are bound to be some breaking changes here and there. Most of these are not change that app developers need to worry themselves with, but something that component authors would need to deal with. If you’re using third-party components/packages that have not updated, you’ll want to opt-out of Ivy for now, and open an issue (or better yet, a pull request) against the repo.

Ionic itself will be ready for Ivy when Angular 9.0 is shipped. I’ve been following along and making the necessary updates needed. We recently have merged a pull request and have been testing a build of Ionic and Angular 9.0.

EntryComponents…BYE BYE BYE

If you’ve been working with Angular for some time now, you know that one of the most frustrating things to deal with are entryComponents. entryComponents, for the uninitiated, are components that Angular will load imperatively and not through a template. For Ionic, this means overlay components like Modals and Popovers make heavy use of entryComponent for figuring out what to actually render. From a users perspective, there’s often a bit of a hiccup when working with Modals/Popovers. The process typically goes:

  • Generate a new component
  • Splitting it out into its own module
  • Attempt to load the component in an overlay
  • Get an obscure error about a Module Factory
  • Realize you forgot to add setup entryComponents

This was such a common issue that we even modified the component schematic from Angular to include options for auto-adding components to entryComponents. Thankfully, with 9.0, this is a thing of the past!

With the way components are compiled (thanks to Ivy), entryComponents are no longer needed. So Modals and Popovers just become much easier to think about.

CLI Improvements

In addition to improvements coming to the framework itself, Angular’s CLI is also getting some improvements as well. For starters, when serving your app, the app will automatically be built using AOT. This is a great improvement as we no longer have to deal with different environments for our apps. For example; you serve your app with ionic serve or ng serve and the app builds fine. There are no errors, the app loads, all is well! But, when you go to deploy and do a production build, an error appears. Why is the error there and why did it show up only during production? Well due to how components are built, AOT often is able to find potential errors before they happen at run time. Say you have a click handler like so:

<ion-content>
  <h1>Click the button</h1>
  <ion-button (click)="logEvent($event)">Click me</ion-button>
</ion-content>

And the component class looks like so:

@Component({...})
export class MyComponent{

  constructor(){...}

  logevent(event: any){
    console.log(event)
  }
}

The small error here is that the click handler is for logEvent, but the actual method is called logevent. This would result in a runtime error, which we do not want. Thanks to being able to run AOT when running serve, we can now catch small errors like this and get meaningful feedback before they ever happen.

Another improvement is with differential builds. In previous releases, the Angular CLI would perform two different builds, on for ES5 environments and one for ES2015. This process produced the ES5 builds first, then would go back and rebuild the app for ES2015, which could make your production builds take a long time if the app was rather large. With 9.0, the CLI will now change how this is done. Instead of building the ES5 version, the CLI will do a ES2015 build of your app first. From there, that ES2015 build will go through a much quick build process to produce a ES5 build with the necessary polyfills. This is a small and subtle change, but can make your build time much faster!

Parting Thoughts

Angular 9.0 is still in RC (RC6) as of now and most likely won’t be shipping before the year is over (good news IMO). But with all the improvements we’ve gone over here, Angular 9.0 will be a welcome update that should help every developer be successful! Cheers 🍻

Originally published by https://ionicframework.com

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

What’s new in HTML6

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

ReactJS vs Angular vs Vue: Best Javascript Framework For Your Project

ReactJS vs Angular vs Vue: Best Javascript Framework For Your Project

ReactJS vs Angular vs Vue: Best Javascript Framework For Your Project. This video covers the key differences between ReactJS, Angular and Vue with respect to the following: Use case, Performance, Data binding, Scripting language, Testing, Community support, Growth curve

ReactJS, Angular and Vue have been all the craze the past couple of years. All these tools help developers build fancy user interfaces for web and mobile applications. But if all of them serve the same objective, what do you think makes them stand apart! Well, to address that, this video covers the key differences between ReactJS, Angular and Vue with respect to the following:

  1. Use case 03:11
  2. Performance 03:30
  3. Data binding 04:52
  4. Scripting language 06:05
  5. Testing 06:52
  6. Community support 07:31
  7. Growth curve 08:24

Learn Angular from Scratch and Go from Beginner to Advanced

Learn Angular from Scratch and Go from Beginner to Advanced

In this Angular Tutorial, you'll learn Angular from scratch and go from beginner to advanced in Angular. In this Angular crash course you will learn from scratch. We will assume that you are a complete beginner and by the end of the course you will be at advanced level. This course contain Real-World examples and Hands On practicals.

Complete Angular Course: Go From Zero To Hero

Complete Angular course. Learn Angular from scratch and go from beginner to advanced in Angular.

Welcome to this course "Complete Angular Crash Course: Learn Angular from Scratch and Go from Beginner to Advanced". In this course you will learn from scratch. We will assume that you are a complete beginner and by the end of the course you will be at advanced level. This course contain Real-World examples and Hands On practicals. We will guide you step by step so that you can understand better. This course will allow you to work on the Real-World as a professional.

What you'll learn

  • Learn The Basics
  • Learn Advanced Methods
  • Step By Step Instructions So That You Can Go From Zero To Hero
  • A Complete Tutorial Explaining Everything You Need To Know
  • Real-World Examples With Hands On Tutorials
  • Get Answers To Your Every Single Questions

JavaScript Tutorial: if-else Statement in JavaScript

JavaScript Tutorial: if-else Statement in JavaScript

This JavaScript tutorial is a step by step guide on JavaScript If Else Statements. Learn how to use If Else in javascript and also JavaScript If Else Statements. if-else Statement in JavaScript. JavaScript's conditional statements: if; if-else; nested-if; if-else-if. These statements allow you to control the flow of your program's execution based upon conditions known only during run time.

Decision Making in programming is similar to decision making in real life. In programming also we face some situations where we want a certain block of code to be executed when some condition is fulfilled.
A programming language uses control statements to control the flow of execution of the program based on certain conditions. These are used to cause the flow of execution to advance and branch based on changes to the state of a program.

JavaScript’s conditional statements:

  • if
  • if-else
  • nested-if
  • if-else-if

These statements allow you to control the flow of your program’s execution based upon conditions known only during run time.

  • if: if statement is the most simple decision making statement. It is used to decide whether a certain statement or block of statements will be executed or not i.e if a certain condition is true then a block of statement is executed otherwise not.
    Syntax:
if(condition) 
{
   // Statements to execute if
   // condition is true
}

Here, condition after evaluation will be either true or false. if statement accepts boolean values – if the value is true then it will execute the block of statements under it.
If we do not provide the curly braces ‘{‘ and ‘}’ after if( condition ) then by default if statement will consider the immediate one statement to be inside its block. For example,

if(condition)
   statement1;
   statement2;

// Here if the condition is true, if block 
// will consider only statement1 to be inside 
// its block.

Flow chart:

Example:

<script type = "text/javaScript"> 

// JavaScript program to illustrate If statement 

var i = 10; 

if (i > 15) 
document.write("10 is less than 15"); 

// This statement will be executed 
// as if considers one statement by default 
document.write("I am Not in if"); 

< /script> 

Output:

I am Not in if
  • if-else: The if statement alone tells us that if a condition is true it will execute a block of statements and if the condition is false it won’t. But what if we want to do something else if the condition is false. Here comes the else statement. We can use the else statement with if statement to execute a block of code when the condition is false.
    Syntax:
if (condition)
{
    // Executes this block if
    // condition is true
}
else
{
    // Executes this block if
    // condition is false
}


Example:

<script type = "text/javaScript"> 

// JavaScript program to illustrate If-else statement 

var i = 10; 

if (i < 15) 
document.write("10 is less than 15"); 
else
document.write("I am Not in if"); 

< /script> 

Output:

i is smaller than 15
  • nested-if A nested if is an if statement that is the target of another if or else. Nested if statements means an if statement inside an if statement. Yes, JavaScript allows us to nest if statements within if statements. i.e, we can place an if statement inside another if statement.
    Syntax:
if (condition1) 
{
   // Executes when condition1 is true
   if (condition2) 
   {
      // Executes when condition2 is true
   }
}

Example:

<script type = "text/javaScript"> 

// JavaScript program to illustrate nested-if statement 

var i = 10; 

if (i == 10) { 

// First if statement 
if (i < 15) 
	document.write("i is smaller than 15"); 

// Nested - if statement 
// Will only be executed if statement above 
// it is true 
if (i < 12) 
	document.write("i is smaller than 12 too"); 
else
	document.write("i is greater than 15"); 
} 
< /script> 

Output:

i is smaller than 15
i is smaller than 12 too
  • if-else-if ladder Here, a user can decide among multiple options.The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed.
if (condition)
    statement;
else if (condition)
    statement;
.
.
else
    statement;


Example:

<script type = "text/javaScript"> 
// JavaScript program to illustrate nested-if statement 

var i = 20; 

if (i == 10) 
document.wrte("i is 10"); 
else if (i == 15) 
document.wrte("i is 15"); 
else if (i == 20) 
document.wrte("i is 20"); 
else
document.wrte("i is not present"); 
< /script> 

Output:

i is 20