<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Muhammed Musthafa</title>
    <description>The latest articles on DEV Community by Muhammed Musthafa (@muzsthafa).</description>
    <link>https://dev.to/muzsthafa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1446842%2Fa190ff5d-9d95-4e64-af86-53ce03dff2f5.jpg</url>
      <title>DEV Community: Muhammed Musthafa</title>
      <link>https://dev.to/muzsthafa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muzsthafa"/>
    <language>en</language>
    <item>
      <title>First Hands-On Experience with Angular 17</title>
      <dc:creator>Muhammed Musthafa</dc:creator>
      <pubDate>Wed, 24 Apr 2024 13:25:10 +0000</pubDate>
      <link>https://dev.to/muzsthafa/first-hands-on-experience-with-angular-17-534d</link>
      <guid>https://dev.to/muzsthafa/first-hands-on-experience-with-angular-17-534d</guid>
      <description>&lt;p&gt;The Angular team has introduced a new block template syntax that simplifies complex features and improves developer experience. This new syntax converts complex code into efficient JavaScript instructions, enhancing control flow, lazy loading, and other functionalities.&lt;/p&gt;

&lt;p&gt;Here are the main benefits of the new syntax:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;More Ergonomic and Intuitive&lt;/strong&gt;: The syntax is closer to JavaScript, making it easier for developers to understand and reducing the need to frequently reference documentation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Type Checking&lt;/strong&gt;: The syntax optimizes type narrowing, which helps improve type checking and catch errors earlier during development.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Build-Time Optimization&lt;/strong&gt;: Because the new syntax operates primarily at build-time, it has minimal impact on runtime performance. This can decrease your bundle size by up to 30 kilobytes and improve your Core Web Vital scores.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automatic Availability&lt;/strong&gt;: The new block syntax is automatically available in your templates without needing any additional imports.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance Improvements&lt;/strong&gt;: Significant performance improvements are a result of this new syntax, which we will discuss in more detail soon.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm really happy with these new syntax updates! They streamline the process of writing conditional and iterative logic in Angular templates, making it easier for developers to efficiently work with the framework.&lt;/p&gt;

&lt;h3&gt;
  
  
  New and Improved Conditional Statements
&lt;/h3&gt;

&lt;p&gt;Here's a side-by-side comparison of the traditional &lt;code&gt;*ngIf&lt;/code&gt; directive and the new block template syntax for conditional statements.&lt;/p&gt;

&lt;h4&gt;
  
  
  Traditional &lt;code&gt;*ngIf&lt;/code&gt; Statement:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"loggedIn; else anonymousUser"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  The user is logged in
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ng-template&lt;/span&gt; &lt;span class="na"&gt;#anonymousUser&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  The user is not logged in
&lt;span class="nt"&gt;&amp;lt;/ng-template&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  New Block Template Syntax:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;if (loggedIn) {
  &lt;span class="c"&gt;&amp;lt;!-- The user is logged in --&amp;gt;&lt;/span&gt;
  The user is logged in
} else {
  &lt;span class="c"&gt;&amp;lt;!-- The user is not logged in --&amp;gt;&lt;/span&gt;
  The user is not logged in
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the new syntax:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The control flow is more direct and familiar to developers accustomed to writing JavaScript.&lt;/li&gt;
&lt;li&gt;The syntax is more straightforward and doesn't require the &lt;code&gt;*ngIf&lt;/code&gt; and &lt;code&gt;ng-template&lt;/code&gt; directives.&lt;/li&gt;
&lt;li&gt;This new syntax is automatically available in your templates without needing any additional imports.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Switch Statement
&lt;/h3&gt;

&lt;p&gt;Here's a comparison of the traditional &lt;code&gt;*ngSwitch&lt;/code&gt; directive and the new block template syntax for switch statements.&lt;/p&gt;

&lt;h4&gt;
  
  
  Traditional &lt;code&gt;ngSwitch&lt;/code&gt; Statement:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;[ngSwitch]=&lt;/span&gt;&lt;span class="s"&gt;"accessLevel"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;admin-dashboard&lt;/span&gt; &lt;span class="na"&gt;*ngSwitchCase=&lt;/span&gt;&lt;span class="s"&gt;"'admin'"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;moderator-dashboard&lt;/span&gt; &lt;span class="na"&gt;*ngSwitchCase=&lt;/span&gt;&lt;span class="s"&gt;"'moderator'"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;user-dashboard&lt;/span&gt; &lt;span class="na"&gt;*ngSwitchDefault&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  New Block Template Syntax:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@switch (accessLevel) {
  @case ('admin') { &lt;span class="nt"&gt;&amp;lt;admin-dashboard/&amp;gt;&lt;/span&gt; }
  @case ('moderator') { &lt;span class="nt"&gt;&amp;lt;moderator-dashboard/&amp;gt;&lt;/span&gt; }
  @default { &lt;span class="nt"&gt;&amp;lt;user-dashboard/&amp;gt;&lt;/span&gt; }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  For Loop
&lt;/h3&gt;

&lt;p&gt;Here's an example of how the new block template syntax compares with the traditional &lt;code&gt;*ngFor&lt;/code&gt; directive for for loops.&lt;/p&gt;

&lt;h4&gt;
  
  
  New Block Template Syntax:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@for (user of users; track user.id) {
  {{ user.name }}
} @empty {
  Empty list of users
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;@for&lt;/code&gt; statement uses a new diffing algorithm and has a more optimal implementation compared to &lt;code&gt;*ngFor&lt;/code&gt;, making it up to 90% faster.&lt;/p&gt;

&lt;p&gt;Overall, the new block template syntax in Angular 17 offers a more direct and human-readable approach to control flow, making it easier for developers to write clean and efficient code. This, in turn, improves the overall developer experience and performance of Angular applications. I'm really happy with these new syntax updates!&lt;/p&gt;

</description>
      <category>angular</category>
      <category>html</category>
      <category>typescript</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
