{"id":27089,"date":"2020-04-08T00:00:00","date_gmt":"2020-04-07T22:00:00","guid":{"rendered":"https:\/\/blexin.com\/angular-9-cosa-cambia-e-perche-usarlo\/"},"modified":"2021-05-20T18:28:07","modified_gmt":"2021-05-20T16:28:07","slug":"angular-9-what-changes-and-why-use-it","status":"publish","type":"post","link":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/","title":{"rendered":"Angular 9: what changes and why use it"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"608\" data-attachment-id=\"27053\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/attachment\/top00-1-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1.png?fit=1024%2C608&amp;ssl=1\" data-orig-size=\"1024,608\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"top00-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1.png?fit=1024%2C608&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1.png?resize=1024%2C608&#038;ssl=1\" alt=\"\" class=\"wp-image-27053\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1-980x582.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1-480x285.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In our job, it\u2019s very challenging to follow the continuous evolution of the frameworks and development tools. In this article, we will see what\u2019s new in Angular 9, why it is a remarkable version, and why it is worthful test it as soon as possible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The expected release date for the ninth version was November 2019, but the official announcement by&nbsp;<a href=\"https:\/\/blog.angular.io\/version-9-of-angular-now-available-project-ivy-has-arrived-23c97b63cfa3\" target=\"_blank\" rel=\"noreferrer noopener\">Stephen Fluin<\/a>&nbsp;arrived only on February 6th. There were a lot of criticisms, maybe due to the natural diffidence around the Angular team, heir of that dramatic transitioning from Angular.js to version 2.0.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before going into the details, please note that in this article I will use version 9.1, published on March 26th.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"404\" height=\"352\" data-attachment-id=\"27056\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/attachment\/image01-4-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image01-4.png?fit=404%2C352&amp;ssl=1\" data-orig-size=\"404,352\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image01-4\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image01-4.png?fit=404%2C352&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image01-4.png?resize=404%2C352&#038;ssl=1\" alt=\"\" class=\"wp-image-27056\" srcset=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image01-4.png?w=404&amp;ssl=1 404w, https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image01-4.png?resize=300%2C261&amp;ssl=1 300w\" sizes=\"auto, (max-width: 404px) 100vw, 404px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Version 9 is relevant because it introduces, by default,&nbsp;<strong>Ivy<\/strong>, a new pipeline for compilation and rendering (available for testing also in version 8).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Why this rewriting? First of all, a big part of web traffic comes from smartphones and tablets. The main challenge for a front developer is to load a web application as fast as possible, taking into account the volatility of an internet connection. The first step is to reduce the bundle size produced by the framework. The Ivy compiler has been designed to remove parts of Angular that aren\u2019t being used via&nbsp;<a href=\"https:\/\/webpack.js.org\/guides\/tree-shaking\/\" target=\"_blank\" rel=\"noreferrer noopener\">tree-shaking<\/a>&nbsp;and to generate less code for each Angular component. Small apps and large apps can see the most dramatic size savings while medium-sized apps should see bundle sizes that are only slightly smaller.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"680\" height=\"386\" data-attachment-id=\"27058\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/attachment\/image02-3-2-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image02-3.png?fit=680%2C386&amp;ssl=1\" data-orig-size=\"680,386\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image02-3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image02-3.png?fit=680%2C386&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image02-3.png?resize=680%2C386&#038;ssl=1\" alt=\"\" class=\"wp-image-27058\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image02-3.png 680w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image02-3-480x272.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 680px, 100vw\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The new Debug experience<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s create a new project using the ng new command and the &#8211;minimal option that removes all the files necessary for the testing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ng new my-first-demo--minimal --style=css<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let us suppose to have a father component called ProductListComponent and its son called ProductDetails. Starting from this situation, let\u2019s see how the debug experience in Angular changes using the Chrome developer tools. Select our father component in the&nbsp;<strong>Components<\/strong>&nbsp;panel, and let\u2019s move to the console.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"637\" data-attachment-id=\"27061\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/attachment\/image04-3-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image04-3.png?fit=1501%2C933&amp;ssl=1\" data-orig-size=\"1501,933\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image04-3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image04-3.png?fit=1024%2C637&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image04-3.png?resize=1024%2C637&#038;ssl=1\" alt=\"\" class=\"wp-image-27061\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image04-3-980x609.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image04-3-480x298.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Inside the console, we can access a new object called&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/angular.io\/api\/core\/global#entry-point-exports\" target=\"_blank\"><strong>ng<\/strong><\/a>, designed to improve the debugging experience. Let\u2019s start associating a variable to the selected component, available through the $0 alias. The ng api returns the component with ng.getContext($0).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"100\" data-attachment-id=\"27063\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/attachment\/image05-3-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image05-3.png?fit=1000%2C100&amp;ssl=1\" data-orig-size=\"1000,100\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image05-3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image05-3.png?fit=1000%2C100&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image05-3.png?resize=1000%2C100&#038;ssl=1\" alt=\"\" class=\"wp-image-27063\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image05-3.png 1000w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image05-3-980x98.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image05-3-480x48.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1000px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We can clone the first product, modify it, show the differences with a console.table<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"427\" data-attachment-id=\"27065\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/attachment\/image06-3-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image06-3.png?fit=1000%2C427&amp;ssl=1\" data-orig-size=\"1000,427\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image06-3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image06-3.png?fit=1000%2C427&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image06-3.png?resize=1000%2C427&#038;ssl=1\" alt=\"\" class=\"wp-image-27065\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image06-3.png 1000w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image06-3-980x418.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image06-3-480x205.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1000px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">and, finally, invoke ng.applyChanges($0) to force the&nbsp;<strong>change detection<\/strong>&nbsp;in Angular. We can also invoke the methods of the selected component to emulate the click on a button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"498\" height=\"251\" data-attachment-id=\"27068\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/attachment\/image07-2-2-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image07-2.png?fit=498%2C251&amp;ssl=1\" data-orig-size=\"498,251\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image07-2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image07-2.png?fit=498%2C251&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image07-2.png?resize=498%2C251&#038;ssl=1\" alt=\"\" class=\"wp-image-27068\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image07-2.png 498w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image07-2-480x242.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 498px, 100vw\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Type checking<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Typescript allows us to find the type errors inside the code but, till now, the templating missed such strong support. Inside the tsconfig.json file, there is a flag called fullTemplateTypeCheck that in Angular 9 is set to true while the false value triggers the&nbsp;<strong>basic type-checking mode<\/strong>. Let\u2019s consider the following case:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&lt;app-product-details\n    &#x5B;store]=&quot;user.address.city&quot; &#x5B;product]=&quot;selectedProduct&quot;&gt;\n&lt;\/app-product-details&gt;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The compiler checks that:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>user is a property belonging to the class component<\/li><li>user is an object with the address property<\/li><li>user.address is an object with the city property<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">In the basic type-checking, the compiler does not verify that the value of user.address.city is assignable to the input called store inside the child component. Besides, the so-called&nbsp;<strong>embedded views<\/strong>, for example, *ngIf, *ngFor, and ng-templates are not checked. Either the results of pipes and the type of $event in event bindings are not checked.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When the fullTemplateTypeCheck flag is set to true, Angular applies a more rigorous type checking. Embedded views are checked, pipes have the correct value type and local references to directives and pipes have the correct type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s consider an *ngFor:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&lt;div *ngFor=&quot;let product of products&quot;&gt;\n    &lt;h3&gt;{{config.title}}&lt;\/h2&gt;\n    &lt;span&gt;Store: {{user.address.city}}&lt;\/span&gt;\n&lt;\/div&gt;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">In basic mode, &lt;h3&gt; and &lt;span&gt; are not checked. In full modality, instead, the compiler checks if config and user exist, but it assumes any type for them!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Angular 9 introduces a third check modality called&nbsp;<strong>strict mode<\/strong>. With it, the framework defines that user inside the span has a User type, and that address is an object with a string property called city.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The strict mode is accessible only with Ivy, setting tsconfig.json like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&quot;angularCompilerOptions&quot;:\n{\n    &quot;strictTemplates&quot;: true,\n    &quot;strictInjectionParameters&quot;: true\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">In the following example:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"575\" height=\"215\" data-attachment-id=\"27071\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/attachment\/image08-2-2-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image08-2.png?fit=575%2C215&amp;ssl=1\" data-orig-size=\"575,215\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image08-2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image08-2.png?fit=575%2C215&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image08-2.png?resize=575%2C215&#038;ssl=1\" alt=\"\" class=\"wp-image-27071\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image08-2.png 575w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image08-2-480x179.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 575px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">I intentionally changed the case for the Id property that is id in the interface definition. Leaving the tsconfig.json in the original version<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&quot;angularCompilerOptions&quot;: \n{\n    &quot;fullTemplateTypeCheck&quot;: true,\n    &quot;strictInjectionParameters&quot;: true\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">the ng build compilation successfully passes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"556\" data-attachment-id=\"27074\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/attachment\/image09-1-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image09-1.png?fit=1265%2C687&amp;ssl=1\" data-orig-size=\"1265,687\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image09-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image09-1.png?fit=1024%2C556&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image09-1.png?resize=1024%2C556&#038;ssl=1\" alt=\"\" class=\"wp-image-27074\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image09-1-1024x556.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image09-1-980x532.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image09-1-480x261.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Passing to the strict mode, instead, the compilation fails.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"527\" data-attachment-id=\"27076\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/attachment\/image10-1-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image10-1.png?fit=1313%2C676&amp;ssl=1\" data-orig-size=\"1313,676\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image10-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image10-1.png?fit=1024%2C527&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image10-1.png?resize=1024%2C527&#038;ssl=1\" alt=\"\" class=\"wp-image-27076\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image10-1-980x505.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image10-1-480x247.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><strong>AOT compilation<\/strong><br><\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Used to launch our apps with the ng serve command, how many times we discovered build errors as we were ready to go to production, executing the ng build &#8211;prod command? It was happening that this last option has started the AOT (Ahead of Time)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Why we need a compilation? What is compiled? When does this compilation happen? We can invoke the Angular compiler at runtime (in the user browser) or at build time in the build process. It has always been said that Angular is portable: it can be executed on every platform with a Javascript VM.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the first case (Just-In.Time Compilation) the typical flux is:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>development of code in Typescript<\/li><li>compilation with&nbsp;<a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/compiler-options.html\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>tsc<\/strong><\/a><\/li><li>bundling, minification and deployment<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The user open the app in her\/his browser starting the following steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>the download of all the Javascript assets<\/li><li>the bootstrap of Angular<\/li><li>the generation of the Javascript for each component in the application<\/li><li>the rendering of the application<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In the Ahead-Of-Time compilation instead we have the following steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>development of code in Typescript<\/li><li>compilation with&nbsp;<a href=\"https:\/\/medium.com\/angular-in-depth\/inside-ivy-exploring-the-new-angular-compiler-ebf85141cee1\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>ngc<\/strong><\/a><\/li><li>bundling, minification and deployment<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">What happens instead when the user open the app in her\/his browser is:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>the download of all the Javascript assets<\/li><li>the bootstrap of Angular<\/li><li>the rendering of the application<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The user experience is better and faster because a more efficient Javascript code is generated in the build phase, and the browser needs only to render the page. The&nbsp;<a href=\"https:\/\/angular.io\/guide\/aot-compiler\" target=\"_blank\" rel=\"noreferrer noopener\">details<\/a>&nbsp;of how the AOT compilation works are behind the scope of this article, but I must confess that I find this world truly fascinating. With Angular 9, the AOT compilation with Ivy is so fast and efficient that now it is used even with ng serve for the builds in the developing phase!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Dependency Injection (DI)<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Other significant news concerns the Dependency Injection. DI is cabled inside Angular and used everywhere to provide all the components with the services they need. The Angular components consume services injected through the constructor.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"502\" height=\"242\" data-attachment-id=\"27079\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/attachment\/image11-1-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image11-1.png?fit=502%2C242&amp;ssl=1\" data-orig-size=\"502,242\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image11-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image11-1.png?fit=502%2C242&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image11-1.png?resize=502%2C242&#038;ssl=1\" alt=\"\" class=\"wp-image-27079\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image11-1.png 502w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image11-1-480x231.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 502px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Any class can be a service. If we precede its definition with a @Injectable() decoration, we can modify the default metadata necessary to Angular to inject it into a component as a dependency. @Injectable() is also needed to mark that a class has its own dependencies.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In its bootstrap phase, Angular creates an&nbsp;<strong>injector<\/strong>&nbsp;available to the whole application. The injector creates the dependencies and manages, inside a&nbsp;<strong>container<\/strong>, all the instances of the dependencies to reuse. Finally, a&nbsp;<strong>provider<\/strong>&nbsp;tells the injector how to obtain or create a dependency.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s consider the following example showing the constructor of a component:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nconstructor(private service: ProductsService) { }\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">When Angular discovers that a component depends on a service, first of all, it checks if the injector has an available instance of that service. If there is not, the registered provider creates it and adds it to the container before passing it to the component.<br>Every service needs at least one provider registered at the application level. Such a provider may be put inside the metadata of the service (the @Injectable() decorator), and in such circumstance, the service is available everywhere in the application. Alternatively, we can register the provider at the module or component level (inside the @NgModule or @Component metadata).&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default, the Angular CLI with the command ng generates registers a provider with the&nbsp;<strong>root injector<\/strong>, meaning that a single shared service instance is created and injected into any class requesting it.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n@Injectable({\n  providedIn: &#039;root&#039;\n})\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The root injector has another advantage: it removes such an instance if it is never used in any component. Inside a specific module, we can register a provider providing the same instance to all the components inside that module.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n@NgModule({\n  providers: &#x5B;\n  ProductsService\n  ],\n  ...\n})\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">When we register a provider at the level component, we create a new instance of the service for each new instance of the component.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n@Component({\n\u00a0\u00a0selector: &#039;app-products-list&#039;,\n\u00a0\u00a0templateUrl: &#039;products-list.component.html&#039;,\n\u00a0\u00a0providers: &#x5B;ProductsService]\n})\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">With Angular 9, when we create an @Injectable() service, we have two new options for&nbsp;<strong>providedIn<\/strong>: platform and any. According to the documentation, the platform option makes a service available as a singleton with an injector that is shared among all the applications on a page. Don\u2019t forget that your SPA index.html page may result in principle host more than one Angular application! In such a way, we succeed in sharing a service surmounting the famous and insuperable&nbsp;<strong>application boundaries<\/strong>!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>providedIn<\/strong>:&nbsp;<strong>any<\/strong>&nbsp;option works like this: service will be provided in every module in which it is used. Any lazy-loaded module (another important feature available since Angular 8) has its instance of the service. Instead, the modules loaded as usual (<strong>eager<\/strong>&nbsp;modules) will continue to share the single instance provided by the root module injector. This new option available for the lazy-loaded modules was designed to avoid side-effect interferences between modules.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Lazy-Loading Components<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We are used to thinking of modules as first-class citizens, even as the most important block in an Angular application. In a module, we declare the components, the directives, pipes, and services. An application can\u2019t exist without a module, but Ivy starts from a different approach: a component may exist without a module. This concept is called&nbsp;<strong>locality:&nbsp;<\/strong>every necessary metadata is local to the component.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s use the ng CLI to generate a component called FirstLazy using the following options:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ng g c first-lazy --flat --skip-import --skip-selector<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We have a single file in which is declared the FirstLazyComponent class without even a selector.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nimport { Component} from &#039;@angular\/core&#039;;\n@Component({\n    template:\n      &lt;p&gt;\n        first-lazy works!\n      &lt;\/p&gt;\n    `\n})\nexport class FirstLazyComponent {\n    constructor() { }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The component we created is not even registered in the root module (app.module.ts).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How can we load it? First of all, let\u2019s insert a button in the&nbsp;<strong>AppComponent<\/strong>&nbsp;with a function associated with the click event.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n@Component({\n    selector: &#039;app-root&#039;,\n    template: `\n      &lt;div&gt;\n          &lt;div&gt;My first lazy component &lt;\/div&gt;\n          &lt;button class=&quot;btn btn-info&quot; (click)=&quot;showLazy()&quot;&gt;Create&lt;\/button&gt;\n      &lt;\/div&gt;\n    `\n})\nexport class AppComponent {\n    title = &#039;my-first-demo&#039;;\n    showLazy(){\n    }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">In the constructor, we can inject an instance of&nbsp;<strong>ViewContainerRef.&nbsp;<\/strong>It is a container in which we can add one or more views to a component. We inject another service called&nbsp;<strong>ComponentFactoryResolver&nbsp;<\/strong>that allows us to create a component by code.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nexport class AppComponent {\n    title = &#039;my-first-demo&#039;;\n    constructor(private cfr: ComponentFactoryResolver,\n                private viewContainerRef: ViewContainerRef) {\n    }\n    showLazy(){\n    }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">In the showLazy() method, first of all, we empty the container from the presence of eventual components. Then we import the component code asynchronously and create it using the ComponentFactoryResolver.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nasync showLazy(){\n\u00a0\u00a0\u00a0\u00a0this.viewContainerRef.clear();\n\u00a0\u00a0\u00a0\u00a0const { FirstLazyComponent } = await import(&#039;.\/first-lazy.component&#039;);\n\u00a0\u00a0\u00a0\u00a0this.viewContainerRef.createComponent(\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.cfr.resolveComponentFactory(FirstLazyComponent)\n\u00a0\u00a0\u00a0\u00a0);\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We have an alternative that gives us significant control over the container. We use an ng-container in which we define a&nbsp;<strong><em>template reference variable<\/em><\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\ntemplate: `\n\u00a0\u00a0\u00a0\u00a0&lt;div&gt;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;div&gt;My first lazy component &lt;\/div&gt;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;button class=&quot;btn btn-info&quot; (click)=&quot;showLazy()&quot;&gt;Create&lt;\/button&gt;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;div class=&quot;myBackground&quot;&gt;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;ng-container #myContainer&gt;&lt;\/ng-container&gt;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/div&gt;\n\u00a0\u00a0\u00a0\u00a0&lt;\/div&gt;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">In the code we use the @ViewChild annotation and we set it in a way that ViewContainerRef points to our #myContainer. Then we modify the method:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nexport class AppComponent {\n    title = &#039;my-first-demo&#039;;\n  \n    @ViewChild(&#039;myContainer&#039;, {read: ViewContainerRef}) myContainer: ViewContainerRef;\n   \n    constructor( private cfr: ComponentFactoryResolver) {}\n  \n    async showLazy(){\n        this.myContainer.clear();\n        const { FirstLazyComponent } = await import(&#039;.\/first-lazy.component&#039;);\n        this.myContainer.createComponent(\n          this.cfr.resolveComponentFactory(FirstLazyComponent)\n        );\n    }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">In the code of our lazy component we can insert a property (I called it message), then create an instance passing as a parameter an injector injected in AppComponent. In this instance, we can set the message property using a service of ours (ProductsService).<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nexport class AppComponent {\n    title = &#039;my-first-demo&#039;;\n  \n    @ViewChild(&#039;myContainer&#039;, {read: ViewContainerRef}) myContainer: ViewContainerRef;\n   \n    constructor(private cfr: ComponentFactoryResolver,\n            private injector: Injector,\n            private myservice: ProductsService) {\n    }\n  \nasync showLazy(){\n    this.myContainer.clear();\n    const { FirstLazyComponent } = await import(&#039;.\/first-lazy.component&#039;);\n    const {instance} = this.myContainer.createComponent(\n        this.cfr.resolveComponentFactory(FirstLazyComponent), null, this.injector);\n    instance.message = this.myservice.message();\n    }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We can check in the network activity how the component was lazy-loaded.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"930\" height=\"433\" data-attachment-id=\"27085\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/attachment\/image14-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image14.png?fit=930%2C433&amp;ssl=1\" data-orig-size=\"930,433\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image14\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image14.png?fit=930%2C433&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image14.png?resize=930%2C433&#038;ssl=1\" alt=\"\" class=\"wp-image-27085\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image14.png 930w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image14-480x223.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 930px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A lazy-loaded component can load other lazy-loaded components as children. The scenario we aim to is to manage our application\u2019s features without the routing. Why should we do it? I would say to have greater control over the loading in high-consuming resources application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Eventually, our lazy-loaded component will need external modules (let\u2019s think to Material, for example). How can we add these modules? We can\u2019t use our AppModule to load them eagerly, because we will produce an error:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>error TS-998001: 'mat-card' is not a known element:<br>1. If 'mat-card' is an Angular component, then verify that it is part of this module.<br>2. If 'mat-card' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The solution is to add to the component file a little module without export declarations. This module will declare only one component: FirstLazyComponent.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n@NgModule({\n    declarations: &#x5B;FirstLazyComponent],\n    imports: &#x5B;CommonModule, MatCardModule]\n})\nclass MyLazyModule {\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">This trick is necessary because now we need a module to import other modules. This will not be true in future Angular versions. The Angular\u2019s future will be based on Ivy and the concept of locality: a component will be completely self-contained.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I hope you liked the new Angular features and that you will use them as soon as possible. The article code is available at the following&nbsp;<a href=\"https:\/\/github.com\/sorrentmutie\/articolo-angular-9\" target=\"_blank\" rel=\"noreferrer noopener\">address<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">See you next time!<\/p>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>New version of the Google front-end framework: let\u2019s see what&#8217;s new<\/p>\n","protected":false},"author":196716245,"featured_media":27053,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"off","_et_pb_old_content":"","_et_gb_content_width":"","_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","inline_featured_image":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"{title}\n\n{excerpt}\n\n{url}","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[688637524],"tags":[688637390,688637392],"class_list":["post-27089","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en","tag-angular-en","tag-web-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Angular 9: what changes and why use it - Blexin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Angular 9: what changes and why use it - Blexin\" \/>\n<meta property=\"og:description\" content=\"New version of the Google front-end framework: let\u2019s see what&#039;s new\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/\" \/>\n<meta property=\"og:site_name\" content=\"Blexin\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-07T22:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-20T16:28:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i2.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1.png?fit=1024%2C608&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"608\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Salvatore Sorrentino\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Salvatore Sorrentino\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/angular-9-what-changes-and-why-use-it\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/angular-9-what-changes-and-why-use-it\\\/\"},\"author\":{\"name\":\"Salvatore Sorrentino\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/354db2bc97cac71c2ceeca21a92d5bed\"},\"headline\":\"Angular 9: what changes and why use it\",\"datePublished\":\"2020-04-07T22:00:00+00:00\",\"dateModified\":\"2021-05-20T16:28:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/angular-9-what-changes-and-why-use-it\\\/\"},\"wordCount\":2038,\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/angular-9-what-changes-and-why-use-it\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/top00-1.png?fit=1024%2C608&ssl=1\",\"keywords\":[\"Angular\",\"Web\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/angular-9-what-changes-and-why-use-it\\\/\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/angular-9-what-changes-and-why-use-it\\\/\",\"name\":\"Angular 9: what changes and why use it - Blexin\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/angular-9-what-changes-and-why-use-it\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/angular-9-what-changes-and-why-use-it\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/top00-1.png?fit=1024%2C608&ssl=1\",\"datePublished\":\"2020-04-07T22:00:00+00:00\",\"dateModified\":\"2021-05-20T16:28:07+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/354db2bc97cac71c2ceeca21a92d5bed\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/angular-9-what-changes-and-why-use-it\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/angular-9-what-changes-and-why-use-it\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/angular-9-what-changes-and-why-use-it\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/top00-1.png?fit=1024%2C608&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/top00-1.png?fit=1024%2C608&ssl=1\",\"width\":1024,\"height\":608},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/angular-9-what-changes-and-why-use-it\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blexin.com\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Angular 9: what changes and why use it\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/\",\"name\":\"Blexin\",\"description\":\"Con noi \u00e8 semplice\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blexin.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/354db2bc97cac71c2ceeca21a92d5bed\",\"name\":\"Salvatore Sorrentino\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a6ec0dc827d2acaa55df9dbf1007e23f6fcb8c9436df52ab48274bb2221085bf?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a6ec0dc827d2acaa55df9dbf1007e23f6fcb8c9436df52ab48274bb2221085bf?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a6ec0dc827d2acaa55df9dbf1007e23f6fcb8c9436df52ab48274bb2221085bf?s=96&d=identicon&r=g\",\"caption\":\"Salvatore Sorrentino\"},\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/author\\\/salvatore-sorrentinoblexin-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Angular 9: what changes and why use it - Blexin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/","og_locale":"en_US","og_type":"article","og_title":"Angular 9: what changes and why use it - Blexin","og_description":"New version of the Google front-end framework: let\u2019s see what's new","og_url":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/","og_site_name":"Blexin","article_published_time":"2020-04-07T22:00:00+00:00","article_modified_time":"2021-05-20T16:28:07+00:00","og_image":[{"width":1024,"height":608,"url":"https:\/\/i2.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1.png?fit=1024%2C608&ssl=1","type":"image\/png"}],"author":"Salvatore Sorrentino","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Salvatore Sorrentino","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/#article","isPartOf":{"@id":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/"},"author":{"name":"Salvatore Sorrentino","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/354db2bc97cac71c2ceeca21a92d5bed"},"headline":"Angular 9: what changes and why use it","datePublished":"2020-04-07T22:00:00+00:00","dateModified":"2021-05-20T16:28:07+00:00","mainEntityOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/"},"wordCount":2038,"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1.png?fit=1024%2C608&ssl=1","keywords":["Angular","Web"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/","url":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/","name":"Angular 9: what changes and why use it - Blexin","isPartOf":{"@id":"https:\/\/blexin.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/#primaryimage"},"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1.png?fit=1024%2C608&ssl=1","datePublished":"2020-04-07T22:00:00+00:00","dateModified":"2021-05-20T16:28:07+00:00","author":{"@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/354db2bc97cac71c2ceeca21a92d5bed"},"breadcrumb":{"@id":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/#primaryimage","url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1.png?fit=1024%2C608&ssl=1","contentUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1.png?fit=1024%2C608&ssl=1","width":1024,"height":608},{"@type":"BreadcrumbList","@id":"https:\/\/blexin.com\/en\/blog-en\/angular-9-what-changes-and-why-use-it\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blexin.com\/en\/"},{"@type":"ListItem","position":2,"name":"Angular 9: what changes and why use it"}]},{"@type":"WebSite","@id":"https:\/\/blexin.com\/en\/#website","url":"https:\/\/blexin.com\/en\/","name":"Blexin","description":"Con noi \u00e8 semplice","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blexin.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/354db2bc97cac71c2ceeca21a92d5bed","name":"Salvatore Sorrentino","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a6ec0dc827d2acaa55df9dbf1007e23f6fcb8c9436df52ab48274bb2221085bf?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a6ec0dc827d2acaa55df9dbf1007e23f6fcb8c9436df52ab48274bb2221085bf?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a6ec0dc827d2acaa55df9dbf1007e23f6fcb8c9436df52ab48274bb2221085bf?s=96&d=identicon&r=g","caption":"Salvatore Sorrentino"},"url":"https:\/\/blexin.com\/en\/author\/salvatore-sorrentinoblexin-com\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/top00-1.png?fit=1024%2C608&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pcyUBx-72V","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/27089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/users\/196716245"}],"replies":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/comments?post=27089"}],"version-history":[{"count":10,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/27089\/revisions"}],"predecessor-version":[{"id":31119,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/27089\/revisions\/31119"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media\/27053"}],"wp:attachment":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media?parent=27089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/categories?post=27089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/tags?post=27089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}