Ivy: The Game Changer in Angular 9 | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (173).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (215)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (132)JavaScript  (220)Microsoft  (118)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (912)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (158)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (147)Chart  (130)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (625)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (505)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (386)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (589)What's new  (331)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Ivy The Game Changer in Angular 9

Ivy: The Game Changer in Angular 9

Even though Angular 9 has some extraordinary updates like improved ng update, support for TypeScript, and inline rendering support for YouTube and Google Maps, the default Ivy compiler has grabbed the attention of developers worldwide with its unbeatable features.

In this blog, we’ll dive into some interesting topics about the Ivy compiler:

Ivy: The next-generation compiler

Angular 9 is available with the awesome features of Ivy, the next-generation compilation and rendering pipeline.

Ivy is the default compiler from Angular version 9 onwards. In the previous version, the View Engine was the default compiler, which produced larger bundle sizes. Ivy uses tree shaking to remove unused code in applications.

The following screenshot illustrates how Ivy improves the application bundle size in Angular 9.

Ivy size improvements
Source: Angular blog

How Ivy improves your application architecture 

Ivy improves application architecture compared to previous versions of Angular. It enhances existing applications as follows:

  • Ivy makes Angular applications simpler, smaller, and faster.
  • Reduces bundle sizes from Angular 8 by an average of 30%.
  • Accelerates application building and compilation.
  • Smarter recompilation, resulting in 40 to 50% reduction in time to compile.
  • Improved speed of internationalization (i18n).
  • Easy debugging mode.
  • Improved build times, with AOT enabled by default.
  • Faster testing.
  • Improved CSS class and style binding.
  • Improved strict type checking.
  • Improved build errors.

A whole new way to build Ivy apps 

StackBlitz is one of the most useful online code editors for deploying Angular apps. Its most recent 2020 version provides:

  • Theme support
  • Auto-import support
  • Zen mode
  • 5x faster UI bundling
  • Ivy support

The following screenshots from the official Angular site illustrate the steps to enable the Ivy compiler in StackBlitz.

Default Enable Ivy option in Settings section

  • Within the json file, you will find enableIvy set to true within angularCompilerOptions as shown in the following screenshot.

enableIvy set to true in tsconfig.json file

Stronger type checking in templates with Ivy

Stronger template and strict type checking are enabled in Angular version 8 and above. The strictTemplates option provides the strongest type checking in templates. It is like the typescript strict flag that checks the expressions and bindings within the templates of TypeScript applications.

In the following code, fullTemplateTypeCheck and strictTemplates flags in the TypeScript configuration filetsconfig.json, are set to true.

"angularCompilerOptions": 
{ 
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true 
}

Here are some reasons template checking is useful:

  • Faster debugging
  • Fewer runtime glitches
  • More meaningful tests

The phantom of the template error

Three types of template type checking are available in Ivy:

  • Basic mode
  • Full mode
  • Strict mode

Basic mode

In basic mode, the fullTemplateTypeCheck flag is set to false in the tsconfig.json file. It validates only the top-level expressions in a template just like the following one.

"angularCompilerOptions": {
    "fullTemplateTypeCheck": false,
    "strictInjectionParameters": true
  }

Example:

   <div>{{ heroes.Id }} {{ heroes.name }}</div>
heroes: Hero = 
    { id: 10, name: "Landon" };

Here, type checking has been done only on heroes, not in the Id. Only the first term heroes is used for checking.

Full mode

In full mode, the fullTemplateTypeCheck flag is set to true, as in the following code. Angular is more aggressive in this type checking within templates. Full mode verifies all levels to check whether an object exists.

“angularCompilerOptions”: {
    “fullTemplateTypeCheck”: true,
    “strictInjectionParameters”: true
  }

Example:

  <div>{{ heroes.Id }} {{ heroes.name }}</div>
   
heroes: Hero = 
    { id: 10, name: "Landon" };

Here, type checking has been done for the entire hero.Id. The following screenshot shows an error in the template of the component AppComponent as the property Id does not exist in it.

Error showing property Id is not existing

Strict mode

In strict mode, the fullTemplateTypeCheck flag is set to true. Strict mode is a superset of full mode and can be accessed by setting the strictTemplates flag to true like in the following code.

   
"angularCompilerOptions": {
  "fullTemplateTypeCheck": true,
   "strictInjectionParameters": true,
    "strictTemplates": true
}

Example:

<ul>
 <li *ngFor="let hero of heroes; trackBy: trackByHero">
  <div>{{ hero.Id }} {{ hero.name }}</div>
 </li>
</ul>
   
  heroes: Hero[] = [
    { id: 10, name: "Landon" },
    { id: 20, name: "Ella" },
    { id: 30, name: "Madelyn" },
    { id: 40, name: "Haley" }
  ];
  trackByHero(hero: Hero) { return hero.id; }      

While compiling the template, you will see the template type checking. As shown in the following screenshot, the error appears when you compile the template.
Error appears during template compilation

Improved CSS class and style binding

In Angular version 9, within the HTML template itself, you will be able to use style variables like in the following code example.

https://stackblitz.com/edit/class-and-style-binding?file=app%2Fsub.component.html

   
<!--Class Binding -->
<h2>{{tittle1}}</h2>
<div [class.myclass]="applyclass">Apply Class</div><br>

<!-- Style Binding -->
<h2>{{tittle2}}</h2>
<div [style.color]="applystyle? 'blue':'orange'">Style binding</div>`


  public tittle1="This is Class Binding";
  public applyclass= true;

    public tittle2="This is Style Binding";
   public applystyle= true;

Note: Strict mode helps to reduce runtime errors by 15%.

Conclusion

In this blog, we have discussed some important features and concepts of the Ivy compiler in Angular version 9 and have seen how it differs from the previous version of the Angular framework.

For Angular developers, Syncfusion provides over 65+ high-performance, lightweight, modular, and responsive Angular components to speed up your development.

If you are already a customer, you can download our Angular package from the License and Downloads page. If you are not yet a customer, you can try our 30-day free trial to check out all our Angular components have to offer. You can also explore samples in our GitHub repository and ask any questions in the issues section.

Please share your feedback in the comments section below. If you have any questions about Syncfusion Angular products, you can contact us through our support forumDirect-Trac, or feedback portal. We are always happy to assist you!

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed