<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Swapnil Chidrawar on Medium]]></title>
        <description><![CDATA[Stories by Swapnil Chidrawar on Medium]]></description>
        <link>https://medium.com/@swapnilchidrawar?source=rss-2befc79c32ca------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*tXta0q-VwgkxBVIvXqzHgQ.jpeg</url>
            <title>Stories by Swapnil Chidrawar on Medium</title>
            <link>https://medium.com/@swapnilchidrawar?source=rss-2befc79c32ca------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 19:50:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@swapnilchidrawar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Data Binding in Angular]]></title>
            <link>https://medium.com/@swapnilchidrawar/data-binding-in-angular-5ac3526484c2?source=rss-2befc79c32ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ac3526484c2</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Swapnil Chidrawar]]></dc:creator>
            <pubDate>Wed, 12 Feb 2020 08:45:58 GMT</pubDate>
            <atom:updated>2020-02-12T09:51:47.711Z</atom:updated>
            <content:encoded><![CDATA[<p>data binding in angular is the process of binding data inside the component. we bind data so that, it will be displayed on the browser to user. Lets understand different types of Data Binding in Detail:</p><p>There are specifically 4 types of Data binding used:<br> * String Interpolation.<br> * Property Binding.<br> * Event Binding.<br> * Two way Data-binding.</p><p><strong>String Interpolation:<br></strong>This is the first type of data binding that we used for displaying value of the variables or expressions on browser. In this type we always bind data from typescript file to template file i.e from .ts file to .html file. To bind the data we use special type of syntax as shown in below image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*U6Q-9U0HnR_Eu10hp2SfGA.png" /><figcaption>String Interpolation</figcaption></figure><p>as displayed above, variable named <strong>title </strong>is declared in component’s ts file with some string value <strong>angular-tutorial</strong>. To display this string value on browser we used <strong>String interpolation</strong> syntax in html file. So when variable name is enclosed with the double curly braces we represent it as a string interpolation.</p><p><strong>Property Binding:<br></strong>This is second type of binding which again used to bind data from typescript file to template file i.e from .ts file to .html file. When I learned about it, First question in my mind was, What is the difference between String interpolation and property Binding then? (as both serves the same purpose)</p><p>Actual difference is String Interpolation binds value of variable, to display it on browser, whereas Property binding actually binds data to property of any input element.</p><p>We can have multiple attributes to html elements like disabled, value etc. so to work these attributes dynamically we can make use of <strong>Property binding </strong>syntax as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*wpc3-flX6FDAyo9imIKaUw.png" /><figcaption>Property Binding</figcaption></figure><p>as displayed above in app.component.html file, we have two input fields First and second, and we are using disabled property of it. If we provide disabled property directly to input field, It will always be disabled. We can get rid of this problem by using Property binding. As shown in second input field, we have bound disableTyping variable to disabled property of input field. So in this way, if value of disabledTyping is true input field will be disabled otherwise it will be enabled.</p><p><strong>Event Binding:<br></strong>This is 3rd type of data binding, in which we actually transfer control from template file of component to typescript file of component. i.e from .html file to .ts file. we can make use of this binding type when we wanted to add events to our application. Let’s take an example as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hxobQRjQgc3T767fFLDBMA.png" /><figcaption>Event Binding syntax in template file</figcaption></figure><p>as shown in image, we have added one button named Submit having <strong>click </strong>event bind to it with the help of event binding syntax. So when user clicks on Submit button control get transferred to onSubmit function which is written in components ts file as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MGVsdcdvsxHeZvJL0Trk7g.png" /><figcaption>On Submit function</figcaption></figure><p><strong>Two way Data binding:<br></strong>This is the last type of data binding used in binding process. As a name indicates it is used to bind data in either of the direction. It is very useful when we wanted to show default value but when value changed it should be tracked. Below is the syntax that is used for Two way data binding:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GJsnSFJuk8jVGKmc2IfRiA.png" /><figcaption>Two way data binding</figcaption></figure><p>as you can see in above image, title is the name of the variable which is bounded to input field with the help of two way data binding syntax.</p><blockquote>Most important condition to use Two way data binding is we need to import <strong>FormsModule </strong>from <strong>@angular/core package</strong> in the module file so that we can make use of that. I have displayed in the below image how to import FormsModule in the module file.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-3iFAjXzzB78NmdYkHbYMw.png" /><figcaption>FormsModule import in Module file</figcaption></figure><p>as you can see in app.module.ts file we have imported FormsModule at line number 4 and registered it at line no 19 in imports array.</p><p>In this way we can make use of data binding to bind the data inside the component.</p><p>Also read about my article on Angular compiler working behind the scenes by clicking <a href="https://medium.com/@swapnilchidrawar/angular-compiler-behind-scenes-e9aa915114e"><em>here</em></a>.</p><blockquote><strong>Please share your thoughts on this article…</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ac3526484c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Compiler (Behind Scenes)]]></title>
            <link>https://medium.com/@swapnilchidrawar/angular-compiler-behind-scenes-e9aa915114e?source=rss-2befc79c32ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9aa915114e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Swapnil Chidrawar]]></dc:creator>
            <pubDate>Tue, 11 Feb 2020 14:24:02 GMT</pubDate>
            <atom:updated>2020-02-11T14:24:02.321Z</atom:updated>
            <content:encoded><![CDATA[<h3>Angular Compiler (Behind the Scenes)</h3><p><strong>Compilation</strong> is the basic process of converting your code to machine understandable code. Most of the languages takes help from their respective compiler. In this session, We are going to learn about the Angular Compiler. we will also learn about difference between .d.ts and .ts files and at last will learn about compiler features that it offers. So Let’s Start:</p><p><strong>What is Angular Compiler?<br></strong> Main task of Angular Compiler is to translate declarative code that we write to imperative code that browser understands. Basically, In angular we create components, bind data to it, and write lots of declarative syntax but it is by- default does not understand to browser, we need to make them understand by converting it. To do so, Angular uses two types of compilers:<br> 1. Just in time compilation (JIT)<br>2. Ahead of Time compilation (AOT).</p><p><strong>JIT (Just In Time)<br> Just </strong>in time compiler is used for development mode. When we write angular code, we not only write the typescript syntax but also integrate it with the angular ex. we add decorators to classes so that it can be identified as a angular feature. Now, when we build this application using JIT compiler, we are feeding this code to <strong>Typescript Compiler</strong> which at the end translate it to Java script. Now , Decorators which are written in angular code are directly bundled into the javascript files after compilation. When These decorators get executed in browser, they call to angular compiler and run-time get executed.</p><p><strong>AOT(Ahead of time)<br></strong>This is another type of compilation technique, which uses <strong>Angular Compiler</strong> instead of typescript compiler to compile the code. This compiler also do the same thing which Typescript compiler does, but it Pre-compiles the angular decorators and the features that we have written so that we can remove cost of compiling it at run time.</p><p><strong>How Angular Compiler works?</strong></p><figure><img alt="Typescript compiler architecture diagram" src="https://cdn-images-1.medium.com/max/881/1*_11CYamWxc3qrxIEk1A3jQ.png" /><figcaption><strong>Typescript compiler Architecture</strong></figcaption></figure><p>As shown in above diagram, Typescript compiler follows 3 important steps for compiling typescript code into the javascript code. <br>1. Program Creation<br>2. Type Checking<br>3. Emit</p><p>Whereas Angular compiler is built, on top of this Typescript compiler. it Uses all the phases of typescript compiler but it also adds its own two important steps i.e <strong>Analysis </strong>and <strong>Resolution </strong>as shown in below diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pDuz6PxH4AWsdErL6YInRg.png" /><figcaption>Angular Compiler Architecture</figcaption></figure><p>Let’s understand significance of each and every phase:</p><p><strong>Program Creation:<br></strong>This is very first step of compilation process. In which Typescript discovers all the files from your source code. This is important because typescript needs to understand all the files so that it can compile. This process of locating the files is starts from <strong><em>tsconfig.json</em></strong> file. In this, Typescript finds initial set of files of your program and again reads their imports so that it will again find their references. In this way again and again it discovers the typescript files from the application.</p><p><strong>Analysis:<br></strong>This is the second phase of compilation process and it is carried out by angular compiler as Angular adds this phase to compilation process. In this step angular takes full set of files from the program and looks for the classes that are defined. Then it tries to find out one’s which are decorated with the angular decorators. it does this just to understand what are the different parts of application, like components, directives, pipes, services etc. So if it is a component then it starts parsing it’s template files. This process is carried out just to understand features in isolation.</p><p><strong>Resolution:<br></strong>In this phase, it again looks into your application, but now in the context of larger picture. It tries to find out Modules in which components are referenced so that this information will help during optimization and to take better decisions.</p><p><strong>Type Checking:<br></strong>This is the second last step of program compilation in which Angular asks typescript to check for the errors into the code and also in the angular templates so that it can be tracked.</p><p><strong>Emit:<br></strong>This is the last and important step of compilation which converts typescript code so that browser can understand it. During this transmission compiler coverts classes to imperative code in which it also inserts angular snippets if it is needed.</p><p><strong>Let’s Understand Difference between .d.ts files and .ts files:<br></strong>When file whose extension is .ts gets compiled, It’s get converted into .js file which browser understands. This generated compiled files does not have type information of the original files. They just contain imperative code which is ready to execute in browser. So, who keeps this type information then? answer is files whose extension is .d.ts . when compiler compiles original files, it also creates .d.ts files so that it handles the shape of the types which are declared in the original file. <strong><em>Why it is so Important?</em> </strong>Basically when we install new libraries from the NPM typescript needs to know their types so that it can be implemented correctly.</p><p><strong>Compiler Features:<br><em>1. ngModule Scope.<br>2. Partial Evaluation.</em></strong></p><p><strong>ngModule Scope:<br></strong>When we use angular components we also connects/links them so that it will help us for the communication between them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*I-hzK2O7yHVBH9Jg5BVxYg.png" /><figcaption>App Component having reference of home component</figcaption></figure><blockquote>As discussed we have linked now home component to app component using @Input signature, during the compilation.</blockquote><ol><li>it becomes very difficult for compiler to find out component class which is associated with &lt;app-home&gt; element.</li><li>Reason behind this is we never add import for this component.</li><li>So, with the help of modules in the angular we can sort out this problem.</li><li>During compilation step, all the components which are declared in the module are called and relatively association of the component class takes place.</li><li>Now, It becomes very difficult if home component is declared into another module named home Module which is then exported so that it can be used in main module as shown in below diagram:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*4QFaJp2D62GCUh7fbr1bUg.png" /><figcaption>Two modules connection in Angular</figcaption></figure><ol><li>As you can see, Home component is exported from Home Module (known as Export scope ) and this module is imported into the App Module.</li><li>Now during compilation of app component, it considers all the components which are declared in its scope (Compilation scope) and also the exported elements of the imported module (export scope).</li><li>In this way compiler able to figure out that app-home is only be a reference of Home component which we received from the export scope and it compiles it.</li></ol><blockquote>This is optimization that compiler does to help tree shaker. very soon I will post story about Tree shaker.</blockquote><p><strong>Partial Evaluation:<br></strong>Angular compiler contains Typescript interpreters so that during build time it should know actual values of certain expressions that we have written into the angular decorators.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1W03W3uPy9WpgYyGV4ux6g.png" /><figcaption>App Module having dynamic declarations array</figcaption></figure><p>so as shown in above image, compiler needs to understand reference of component array which is declared in somewhere in the code. For this compiler runs typescript code written in decorators and determine the value of the declarations array. So in this way even components declared in the another file we can import it and use it. Thanks to partial evaluation as it detects the import and references the values.</p><p>In this way, Angular compiler works under the hood.</p><blockquote><strong><em>Please share your thoughts on this article…</em></strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9aa915114e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>