<?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 Anmol Shrivastava on Medium]]></title>
        <description><![CDATA[Stories by Anmol Shrivastava on Medium]]></description>
        <link>https://medium.com/@anmolion?source=rss-6f26cbfd12e7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*j2lfsm_SFYsSw7tSAV4V-w.png</url>
            <title>Stories by Anmol Shrivastava on Medium</title>
            <link>https://medium.com/@anmolion?source=rss-6f26cbfd12e7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 20:07:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anmolion/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 Sharing in Unrelated Components — Angular]]></title>
            <link>https://medium.com/@anmolion/data-sharing-in-unrelated-components-angular-70ffc53f27ee?source=rss-6f26cbfd12e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/70ffc53f27ee</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Anmol Shrivastava]]></dc:creator>
            <pubDate>Mon, 06 Apr 2020 08:34:05 GMT</pubDate>
            <atom:updated>2020-04-06T08:34:05.133Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data Sharing in Unrelated Components — Angular</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9eKPxGs4EPaeYuQU8HECCg.png" /></figure><p>If you are making an angular project that has multiple screens and with interactive relations between them then data sharing is an essential concept to understand before diving into your Angular project. There are multiple methods available in Angular to perform data binding or sharing. You can divide them into two different sections, mainly data sharing between <strong>“Related”</strong> or <strong>“Unrelated”</strong> Components. If in your project, components follow a parent-child, siblings or grandchildren you can check my other article <a href="https://medium.com/@s.anmol1994/two-way-data-binding-among-components-in-angular-8-65bd1cce620d">“<strong>Two-Way data binding among components in Angular 8”</strong></a><strong>. </strong>Otherwise, in case of unrelated components, follow along to get started with data sharing using <strong>RxJs BehaviorSubject</strong> technique in Angular.</p><p>You can also use RxJs Subject in services to share data but I prefer to use Behavior Subject because of few reasons</p><ul><li>As BehaviorSubject holds one value, thus when subscribed it will emit the recently updated value immediately.</li><li>Subject does not return the current value immediately when subscribed, it triggers only on .next(value).</li></ul><p>Alright, so now let’s see an example of sharing data via RxJs BehaviorSubject where we are going to update the status variable for two different components and use a service to inject the variable.</p><p>Service :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/462fe1b44664005c53e05bf1d3e91719/href">https://medium.com/media/462fe1b44664005c53e05bf1d3e91719/href</a></iframe><p>Components :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee73cc267e6e5347fca209241d51ad8a/href">https://medium.com/media/ee73cc267e6e5347fca209241d51ad8a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bf559411b8a7b3724d8a373ab9c55d1/href">https://medium.com/media/4bf559411b8a7b3724d8a373ab9c55d1/href</a></iframe><p>I hope you find this article helpful. In case you wanna learn more about RxJs refer this article — <a href="https://xgrommx.github.io/rx-book/why_rx.html">https://xgrommx.github.io/rx-book/why_rx.html</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70ffc53f27ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decode Base64 to Image]]></title>
            <link>https://medium.com/@anmolion/decode-base64-to-image-66b0e4a586e5?source=rss-6f26cbfd12e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/66b0e4a586e5</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[devtips]]></category>
            <dc:creator><![CDATA[Anmol Shrivastava]]></dc:creator>
            <pubDate>Mon, 09 Mar 2020 19:37:24 GMT</pubDate>
            <atom:updated>2020-03-15T06:17:51.663Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-TomSdOXRLibCek5u-wOnw.jpeg" /></figure><p>Code Sample -</p><p>To start with you can use the <a href="https://www.base64-image.de/">base64 image encoding website</a>. To convert base 64 encoded image you will have to use the <a href="https://www.php.net/manual/en/function.base64-decode.php">base64_decode</a> function. To reconstruct the image use this gist.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e10692f75c9f4484b11d4747ee0fb9c/href">https://medium.com/media/7e10692f75c9f4484b11d4747ee0fb9c/href</a></iframe><p>In case you find this code piece useful, don’t forget the claps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66b0e4a586e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two-Way data binding among components in Angular 8]]></title>
            <link>https://medium.com/@anmolion/two-way-data-binding-among-components-in-angular-8-65bd1cce620d?source=rss-6f26cbfd12e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/65bd1cce620d</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[angular8]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Anmol Shrivastava]]></dc:creator>
            <pubDate>Mon, 17 Feb 2020 13:10:18 GMT</pubDate>
            <atom:updated>2020-04-06T06:28:33.074Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G6COy4mr5Tofpdagm6yB-w.jpeg" /></figure><p>While building on angular, whether it is a large scale enterprise app or just a small side project you will definitely find yourself in a stage with a requirement of two-way data binding. Usually, for small apps, you may use a data variable in the same component itself, but as the code and requirements scale up there might be scenarios where there you would need to use the same or multiple variables across different components within the project.</p><p>When it comes to binding there are primarily three different methods that Angular offers.</p><ul><li>Property binding — -&gt; []</li><li>Event binding — -&gt; ()</li><li>Two-way binding (a combination of the two above)— -&gt; [()] — -&gt; this is also called as <strong>“Banana in the box”</strong></li></ul><p>Let’s try to understand these using an example where we manipulate a variable <strong>“accountBalance”.</strong> We will use a parent and a child component; from the parent you can credit an amount by 10 and from the child you can debit the same.</p><h3>Property Binding &amp; Event Binding</h3><p>First, let’s define our parent component.</p><pre>// parent_component.component.ts</pre><pre><a href="http://twitter.com/Component">@Component</a>({<br>  selector: &#39;parent_component&#39;,<br>  templateUrl: &#39;./parent_component.component.html&#39;,<br>  styleUrls: [&#39;./parent_component.component.css&#39;]<br>})<br>export class ParentComponent implements OnInit {<br>    <br>    accountBalance : any;</pre><pre>    ngOnInit() {<br>       this.accountBalance = 500;<br>    }</pre><pre>    creditAccountBalance()<br>    {<br>        this.accountBalance += 10;<br>    }      <br>}</pre><p>Here, <em>accountBalance</em> is a variable declared inside the parent component, we will pass this variable to the child component inside the component selectors.</p><pre>// parent_component.component.html<br>&lt;span&gt; Balance Amount : {{accountBalance}} &lt;/span&gt;<br>&lt;button <strong>(click)=creditAccountBalance()</strong>&gt; Add Amount &lt;/button&gt;</pre><pre>&lt;child_component <strong>[accountBalance]=&quot;accountBalance&quot;</strong>&gt; &lt;/child_component&gt;</pre><p>If a component variable is passed as an Html attribute <em>(like in that of the last line)</em> it is known as property binding.</p><p>To have angular call some code when an action/event is performed we use event change binding. A classic example of event binding is click/change which we have used in the above example as well.</p><p>Now, let’s define our child component with a function to debit the account balance by 10. The child component can listen to the property bound variable using the<strong> `@Input() decorator`.</strong></p><pre>// child_component.component.ts</pre><pre><a href="http://twitter.com/Component">@Component</a>({<br>  selector: &#39;child_component&#39;,<br>  templateUrl: &#39;./child_component.component.html&#39;,<br>  styleUrls: [&#39;./child_component.component.css&#39;]<br>})<br>export class ChildComponent implements OnInit {<br>    <a href="http://twitter.com/Input"><strong>@Input</strong></a><strong>(&#39;accountBalance&#39;) accountBalance: any;</strong></pre><pre>    debitAccountBalance()<br>    {<br>        this.accountBalance -= 10;<br>    }      <br>}</pre><pre>// child_component.component.html<br>&lt;button <strong>(click)=debitAccountBalance()</strong>&gt; Debit Amount &lt;/button&gt;</pre><p>Here, the amount will be reduced by 10 but, since property binding only provides a unidirectional binding i.e change made from the parent controller will be recognized inside the child controller but not vice-versa. Thus, the debited “accountBalance” value will not be reflected in the parent component.</p><h3>Two Way Binding</h3><p>To solve the problem which was addressed above, we would need to use <strong>Banana in the box </strong>method. But before that let’s understand how can you write custom event binding functions. First, we would have to change our parent Html a bit.</p><pre>// parent_component.component.html<br>&lt;span&gt; Balance Amount : {{accountBalance}} &lt;/span&gt;<br>&lt;button (click)=creditAccountBalance()&gt; Add Amount &lt;/button&gt;</pre><pre>&lt;child_component [accountBalance]=&quot;accountBalance&quot; <strong>(accountBalanceChange)=&quot;this.accountBalance= $event&quot;</strong>&gt; &lt;/child_component&gt;</pre><p>To broadcast this event we would also have to bind the event inside child component using the <strong>@OUTPUT</strong> decorator.</p><pre>// child_component.component.ts</pre><pre><a href="http://twitter.com/Component">@Component</a>({<br>  selector: &#39;child_component&#39;,<br>  templateUrl: &#39;./child_component.component.html&#39;,<br>  styleUrls: [&#39;./child_component.component.css&#39;]<br>})<br>export class ChildComponent implements OnInit {<br>    <a href="http://twitter.com/Input">@Input</a>(&#39;accountBalance&#39;) accountBalance: any;<strong><br>    </strong><a href="http://twitter.com/Output"><strong>@Output</strong></a><strong>() accountBalanceChange = new EventEmitter();</strong></pre><pre>debitAccountBalance()<br>    {<br>        this.accountBalance -= 10;<br>        <strong>this.accountBalanceChange.emit(this.accountBalance);</strong></pre><pre>    }      <br>}</pre><p>With this amount debited from child component will be acknowledged inside the parent component as well. A better way to write the same binding but using BANANA IN THE BOX [🍌]would be something like this.</p><pre>// parent_component.component.html<br>&lt;span&gt; Balance Amount : {{accountBalance}} &lt;/span&gt;<br>&lt;button (click)=creditAccountBalance()&gt; Add Amount &lt;/button&gt;</pre><pre>&lt;child_component [accountBalance]=&quot;accountBalance&quot; <strong>[(accountBalance)]=&quot;accountBalance&quot;</strong>&gt; &lt;/child_component&gt;</pre><p>The [()] syntax is easy to demonstrate when the element has a settable property called x and a corresponding event named xChange.</p><p>Bravvvoooooo… that’s how you achieve a two-way binding between components. Further, you can add other child components and the value change inside one will be acknowledged among other children and parent components as well.</p><p>I hope, this article was helpful !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65bd1cce620d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JS load conflicts — Angular]]></title>
            <link>https://medium.com/@anmolion/js-load-conflicts-angular-7d10259d9ce3?source=rss-6f26cbfd12e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d10259d9ce3</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[angular8]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webflow]]></category>
            <dc:creator><![CDATA[Anmol Shrivastava]]></dc:creator>
            <pubDate>Tue, 31 Dec 2019 07:32:58 GMT</pubDate>
            <atom:updated>2020-02-18T10:28:14.149Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to fix JS load conflicts — Angular 2+</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wA9MnWYI0nlkqwx_uuIO1w.jpeg" /></figure><p>If you are building a full product using Angular, it is very obvious that soon after you start exploring and building you might want to include multiple 3rd party JS libraries. Often these libraries have dependencies, for example, a calendar or an image selector library might require jQuery. Thus, initiating and loading can sometimes get tricky for JS that required loading based on hierarchy.</p><p>During one of my projects, I was using <a href="https://webflow.com/"><strong><em>Webflow</em></strong></a> as my CMS i.e all design, animations and transitions were implemented inside webflow project. How and Why use Webflow is a topic for a separate article. Nonetheless, when you export your project there it provides you with HTML templates and other js and image assets that are required to be imported in the project.</p><p>In angular to import js by default, we put those in angular.json file sample —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b4f1aa3f009fc521e629a44f74ae3d6/href">https://medium.com/media/2b4f1aa3f009fc521e629a44f74ae3d6/href</a></iframe><p>Here you can see that there are 3 different scripts webflow, jquery, and scripts(my own custom script). Webflow requires jquery to be loaded first but if you put both these in angular.json, some functionalities of webflow might not work as expected. Thus, in order to resolve the conflict, you can remove the webflow from the angular.json file and instead load it inside scripts.js using jQuery ready command and everything works like a charm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cbee9e8d5f3c751f4c874ec93610fa0/href">https://medium.com/media/7cbee9e8d5f3c751f4c874ec93610fa0/href</a></iframe><p>Please feel free to leave your comments/doubts or improvements as suggestions. Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d10259d9ce3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GET API in Angular 8]]></title>
            <link>https://medium.com/@anmolion/get-api-in-angular-8-2a9b0a69b900?source=rss-6f26cbfd12e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a9b0a69b900</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[angular8]]></category>
            <dc:creator><![CDATA[Anmol Shrivastava]]></dc:creator>
            <pubDate>Wed, 27 Nov 2019 17:30:08 GMT</pubDate>
            <atom:updated>2019-11-27T17:31:20.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LEVWcnihkqG9XGGCroKzYQ.jpeg" /></figure><p>To understand the API request structure, make sure you have a fair bit of understanding of <a href="https://angular.io/guide/observables-in-angular">Observables</a> in <a href="https://angular.io/">Angular</a>. However, for this tutorial, it is not a pre-request, but it is anyway recommended to have an understanding as it will be required once you get deep into API utilization.</p><p>If you have already created your components read ahead otherwise follow the <a href="https://angular.io/start">Getting started guide for Angular.</a> Otherwise, proceed ahead.</p><p>As the first step, you will have to import modules like HttpHeaders, HttpClient, HttpResponse &amp; Observable.</p><pre>import { Component, OnInit } from &#39;<a href="http://twitter.com/angular/core">@angular/core</a>&#39;;<br>import { HttpHeaders, HttpClient, HttpResponse } from &#39;<a href="http://twitter.com/angular/common">@angular/common</a>/http&#39;;<br>import { Observable } from &#39;rxjs&#39;;</pre><p>Let’s consider, an API which provides a JSON response of members of a team and which looks something like this</p><pre>{<br>  &quot;data&quot;: [<br>    {<br>      &quot;id&quot;: 4490,<br>      &quot;is_active&quot;: 1,<br>      &quot;firstname&quot;: &quot;Jon&quot;,<br>      &quot;lastname&quot;: &quot;Doe&quot;,<br>      &quot;email&quot;: &quot;<a href="/service/mailto:jondoe@mailus.com">jondoe@mailus.com</a>&quot;<br>    },<br>    {<br>      &quot;id&quot;: 4410,<br>      &quot;is_active&quot;: 1,<br>      &quot;firstname&quot;: &quot;Jake&quot;,<br>      &quot;lastname&quot;: &quot;Adams&quot;,<br>      &quot;email&quot;: &quot;<a href="/service/mailto:jakeadams@mailus.com">jakeadams@mailus.com</a>&quot;<br>    }<br>  ],<br>  &quot;error&quot;: false,<br>  &quot;message&quot;: &quot;OK&quot;<br>}</pre><p>Let’s define a variable as the API endpoint</p><pre>private _teamMembersAPI: string = &quot;<a href="http://api.omnify.tex/v1/business/578/team">A</a>PI_URL&quot;;</pre><p>Next, obviously the API might require you to have some sort of Authentication, for this we will have to use the HttpHeaders module, an example for JWT based auth is given below. Also, make sure you have added the HttpClient module in the constructor.</p><pre>httpOptions = {<br> headers: new HttpHeaders({<br>   &#39;Authorization&#39;: &#39;Bearer &lt;token_here&gt;&#39;<br> })<br>};</pre><pre>constructor(private http: HttpClient) { }</pre><p>Now let’s define some variables and a function to call the GET API.</p><pre>import { Component, OnInit } from &#39;<a href="http://twitter.com/angular/core">@angular/core</a>&#39;;<br>import { HttpHeaders, HttpClient, HttpResponse } from &#39;<a href="http://twitter.com/angular/common">@angular/common</a>/http&#39;;<br>import { Observable } from &#39;rxjs&#39;;</pre><pre><a href="http://twitter.com/Component">@Component</a>({<br>  selector: &#39;app-teamaccess&#39;,<br>  templateUrl: &#39;./teamaccess.component.html&#39;,<br>  styleUrls: [&#39;./teamaccess.component.css&#39;]<br>})</pre><pre>export class TeamComponent implements OnInit {</pre><pre>private _teamMembersAPI: string = &quot;<a href="http://api.omnify.tex/v1/business/578/team">A</a>PI_URL&quot;;</pre><pre>httpOptions = {<br> headers: new HttpHeaders({<br>   &#39;Authorization&#39;: &#39;Bearer Tokenhere&#39;<br> })<br>};</pre><pre>constructor(private http: HttpClient) { }</pre><pre>ngOnInit() {<br>}</pre><pre>teamMembers: any;<br>response: any;<br>apiResponse: any;<br>teamMembersListArray: any;</pre><pre>getTeamMembers() {</pre><pre>this.teamMembers = this.http.get(this._teamMembersAPI, this.httpOptions);</pre><pre>this.teamMembers.subscribe((response: any[])=&gt;{<br>      // call handle response functions here !!!<br>      this.apiResponse = response;<br>      this.teamMembersListArray = this.apiResponse.data;<br>    }, (rejection)=&gt;{<br>      // retry, alert, message etc...<br>      console.log(&#39;something is wrong&#39;);<br>    });</pre><pre>console.log(&#39;yolo!&#39;);<br>  }</pre><pre>}</pre><p>Here, this.http.get returns an observable, which we would need to listen for performing further actions, hence the use of subscribe() this also lets us handle success and rejection states.</p><h3>Conclusion</h3><p>In this tutorial, we used Angular 8 to build a simple news application that retrieves data from a JSON REST API using the get() method of HttpClient. We’ve seen how to subscribe to the RxJS Observable returned by the get() method.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a9b0a69b900" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>