<?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: NagarLalit</title>
    <description>The latest articles on DEV Community by NagarLalit (@nagarlalit).</description>
    <link>https://dev.to/nagarlalit</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%2F461042%2Ff321d2f1-f85b-4113-932b-934da20d28c5.png</url>
      <title>DEV Community: NagarLalit</title>
      <link>https://dev.to/nagarlalit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nagarlalit"/>
    <language>en</language>
    <item>
      <title>Angular Migrate To New Control Flow Syntax</title>
      <dc:creator>NagarLalit</dc:creator>
      <pubDate>Fri, 29 Aug 2025 16:59:23 +0000</pubDate>
      <link>https://dev.to/nagarlalit/angular-migrate-to-new-control-flow-syntax-421n</link>
      <guid>https://dev.to/nagarlalit/angular-migrate-to-new-control-flow-syntax-421n</guid>
      <description>&lt;p&gt;From Angular V17, the team has introduced new syntax for if-else, for loop, and switch case.&lt;/p&gt;

&lt;p&gt;You can update the existing code to the new syntax using the command available in angular CLI.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://angular.dev/reference/migrations/control-flow" rel="noopener noreferrer"&gt;Official documentation link :-&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following are the steps to migrate&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to the root folder of the project in command line tool and execute following command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng generate @angular/core:control-flow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;After executing the previous command, it will ask for path to run the migration. You can enter dot (.) to proceed further&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F582k3of3ei6my4k8n49g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F582k3of3ei6my4k8n49g.png" alt="angular control flow migration command" width="638" height="65"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Then it will ask to reformat the templates. Enter Y to continue&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftlvlgoya7magcljvaf4s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftlvlgoya7magcljvaf4s.png" alt="angular control flow migration command" width="640" height="86"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The command will take a couple of minutes to execute, depends on the codebase size. Once migration is successful, you will see the following message if it was not able to migrate certain files
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; WARNING: 2 errors occurred during your migration:

    Template "file-path" encountered 1 errors during migration:
     - parse: Error: The migration resulted in invalid HTML for "file-path". Please check the template for valid HTML structures and run the migration again.

    Template "file-path" encountered 1 errors during migration:
     - *ngFor: Error: Found an aliased collection on an ngFor: "data of data.content as Array". Collection aliasing is not supported with @for. Refactor the code to remove the `as` alias and re-run the migration.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For such files, you will have to either update the syntax manually or correct the issues flagged by CLI and run the migrations again (might not work in every case). For rest of the files, the new syntax should be updated.&lt;/p&gt;

&lt;p&gt;Verify the changes manually or by executing unit and functional test cases.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>angular17</category>
    </item>
    <item>
      <title>How rollup's latest release affected our angular library build</title>
      <dc:creator>NagarLalit</dc:creator>
      <pubDate>Wed, 22 Jun 2022 16:29:09 +0000</pubDate>
      <link>https://dev.to/nagarlalit/how-rollups-latest-release-affected-our-angular-library-build-3j8p</link>
      <guid>https://dev.to/nagarlalit/how-rollups-latest-release-affected-our-angular-library-build-3j8p</guid>
      <description>&lt;p&gt;In one of our project at workplace we are using &lt;a href="https://www.toptal.com/front-end/guide-to-monorepos" rel="noopener noreferrer"&gt;mono-repo&lt;/a&gt; architecture for our angular applications.&lt;br&gt;
Following is the tech stack for the mono repo.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Angular&lt;/li&gt;
&lt;li&gt;Lerna (to manage the packages at multiple application level)&lt;/li&gt;
&lt;li&gt;NPM (package manager)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Folder structure:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project
│   README.md   
│   lerna.json
|   package.json
|   package-lock.json
└───apps
│   │
│   └───angular-app-1
│       │   package.json
│       │   angular.json
│       │   ...
|   |
│   └───angular-app-2
│       │   package.json
│       │   angular.json
│       │   ...
|
└───SDK
|   |
│   └───angular-library
│       │   package.json
|       |   ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The angular library located inside SDK directory is used to share the code between multiple angular applications. Majorly it contains services, translators and utility functions.&lt;br&gt;
The npm package which is used to build angular library is &lt;strong&gt;&lt;em&gt;ng-packagr&lt;/em&gt;&lt;/strong&gt; (for more info visit &lt;a href="https://www.npmjs.com/package/ng-packagr" rel="noopener noreferrer"&gt;this&lt;/a&gt; website)&lt;br&gt;
ng-packagr internally uses rollup for building the angular library. See the highlighted package in below screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffo17im8k8auzuiytx3u7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffo17im8k8auzuiytx3u7.png" alt="ng-packagr's package.json"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have noticed ng-packagr is using caret(^) sign to download the rollup package. It means every package version from &lt;strong&gt;&lt;em&gt;2.0.0&lt;/em&gt;&lt;/strong&gt; till &lt;strong&gt;&lt;em&gt;&amp;lt; 3.0.0&lt;/em&gt;&lt;/strong&gt; will be automatically fetched from npm registry whenever we are going to install the packages.&lt;/p&gt;

&lt;p&gt;When rollup released its version &lt;strong&gt;&lt;em&gt;2.75.3&lt;/em&gt;&lt;/strong&gt; our angular library's build was suddenly started breaking. It throws following error.&lt;br&gt;
&lt;code&gt;Cannot read properties of null (reading 'render')&lt;/code&gt;&lt;br&gt;
&lt;a href="https://github.com/rollup/rollup/issues/4517" rel="noopener noreferrer"&gt;Visit this link to see more details&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remediation&lt;/strong&gt;:-&lt;br&gt;
When we checked the npm error log. We have found out that it was getting generated from rollup.js . But we were not using rollup.js in our root package.json so to know that from where it is getting installed we fired following command to identify the source package.&lt;br&gt;
&lt;code&gt;npm list rollup&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8n5t6ywmqixg16plr8ow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8n5t6ywmqixg16plr8ow.png" alt="npm list result"&gt;&lt;/a&gt;&lt;br&gt;
Then we got to know that it is being used by ng-packagr.&lt;br&gt;
To resolve the issue quickly we added rollup's latest stable version in our root package.json without caret sign due to which the version specified by us was installed instead of the version which is required by ng-packagr.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"rollup": "2.75.2"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It was later fixed by rollup team in another release.&lt;br&gt;
&lt;a href="https://github.com/rollup/rollup/pull/4519" rel="noopener noreferrer"&gt;Visit this link to understand the fix&lt;/a&gt;&lt;/p&gt;

</description>
      <category>angular</category>
      <category>rollup</category>
      <category>lerna</category>
      <category>monorepo</category>
    </item>
    <item>
      <title>Closures &amp; Angular</title>
      <dc:creator>NagarLalit</dc:creator>
      <pubDate>Mon, 02 Aug 2021 13:20:48 +0000</pubDate>
      <link>https://dev.to/nagarlalit/closures-angular-pi9</link>
      <guid>https://dev.to/nagarlalit/closures-angular-pi9</guid>
      <description>&lt;p&gt;During the interview, most of the people are able to answer when asked about Closures and their general examples. But when asked about the same if they have used or seen it anywhere in their angular application most of them failed to provide an example. So I thought to document a basic example of closure in Angular.&lt;br&gt;
Reiterating the definition of Closure as per MDN. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures"&gt;Closures&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Closures
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now breaking up the definition for better understanding.&lt;br&gt;
A closure gives you access to an outer function’s scope from an inner function.&lt;br&gt;
So basically after execution of the outer function, the inner function can remember the scope (e.g. if there are any variables in the outer function the inner function can access them).&lt;br&gt;
So, in Angular, we usually subscribe to any API call inside the ngOnInit function. Something like the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ngOnInit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users?page=1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;data response&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the &lt;strong&gt;subscribe&lt;/strong&gt; and &lt;strong&gt;error&lt;/strong&gt; functions are acting as inner functions and the ngOnInit is acting as an outer function. And we can access any variables or methods of the component using &lt;strong&gt;this&lt;/strong&gt; keyword. This means it remembers the scope of the outer function.&lt;/p&gt;

&lt;p&gt;PS: This is my first blog, apologies if I have made any mistakes. Hope you have liked this one.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>angular</category>
      <category>firstpost</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
