<?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 Danish Jibbran on Medium]]></title>
        <description><![CDATA[Stories by Danish Jibbran on Medium]]></description>
        <link>https://medium.com/@danishjibbran_44045?source=rss-15e7e166e27c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Danish Jibbran on Medium</title>
            <link>https://medium.com/@danishjibbran_44045?source=rss-15e7e166e27c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 23:59:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danishjibbran_44045/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[Angular: Passing data to ng-template]]></title>
            <link>https://medium.com/@danishjibbran_44045/angular-passing-data-to-ng-template-d299e17c5ae2?source=rss-15e7e166e27c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d299e17c5ae2</guid>
            <category><![CDATA[ng-template]]></category>
            <category><![CDATA[ngtemplate-pass-data]]></category>
            <category><![CDATA[passing-data-ng-template]]></category>
            <category><![CDATA[ngtemplateoutlet]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Danish Jibbran]]></dc:creator>
            <pubDate>Sun, 10 Apr 2022 09:12:16 GMT</pubDate>
            <atom:updated>2022-04-10T09:12:16.161Z</atom:updated>
            <content:encoded><![CDATA[<p>In web application development in Angular, we may come up with a situation where we may need to display information based on some conditions. For this purpose, we can use ng-template. However, we may also require to pass data to ng-template; so that, a different type of output is displayed.</p><p>Following example shows this scenario:</p><pre>&lt;div&gt;<br>  &lt;ng-container *ngTemplateOutlet=&quot;myTemplate<strong>, </strong>context<strong>:{</strong>$implicit<strong>: </strong>dataForTemplate<strong>, </strong>extraInfo<strong>: </strong>extraInfo <strong>} </strong>&quot;&gt;<br>  &lt;/ng-container&gt;<br>&lt;/div&gt;<br><br>&lt;ng-template #myTemplate let-data let-extraInfo=&quot;extraInfo&quot;&gt;<br>  <strong>{{</strong>data<strong>.</strong>showName<strong>?  </strong>data<strong>.</strong>name<strong>: </strong>&#39;&#39;<strong>}}<br>  {{</strong>data<strong>.</strong>showAddress<strong>?  </strong>data<strong>.</strong>address<strong>: </strong>&#39;&#39;<strong>}}<br>  {{</strong>extraInfo<strong>.</strong>value<strong>}}<br></strong>&lt;/ng-template&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d299e17c5ae2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular : Dynamically resolving service based on text/enum value]]></title>
            <link>https://medium.com/@danishjibbran_44045/angular-dynamically-resolving-service-based-on-text-enum-value-13cf4bad81a8?source=rss-15e7e166e27c------2</link>
            <guid isPermaLink="false">https://medium.com/p/13cf4bad81a8</guid>
            <category><![CDATA[dynamic-services]]></category>
            <category><![CDATA[dynamicallyresolveservice]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[services]]></category>
            <category><![CDATA[resolve]]></category>
            <dc:creator><![CDATA[Danish Jibbran]]></dc:creator>
            <pubDate>Sun, 10 Apr 2022 05:26:27 GMT</pubDate>
            <atom:updated>2022-04-10T09:14:09.900Z</atom:updated>
            <content:encoded><![CDATA[<h3>Angular: Dynamically resolving service based on text/enum value</h3><p>There may come situations where we need to resolve the services as dependencies dynamically based on text or enum value.</p><p>For example, we have an abstract service called MyCalculatorBase, and it has two implementations: MyFirstCalculator and MySecondCalculator, as shown in the below code:</p><pre>export abstract class MyCalculatorBase <strong>{<br>  </strong>abstract calculate<strong>(</strong>first<strong>: </strong>number<strong>, </strong>second<strong>: </strong>number<strong>): </strong>number<strong>;<br>}<br><br></strong>@Injectable<strong>({<br>  </strong>providedIn<strong>: </strong>&#39;root&#39;<br><strong>})<br></strong>export class MyFirstCalculator extends  MyCalculatorBase <strong>{<br>  </strong>calculate<strong>(</strong>first<strong>: </strong>number<strong>, </strong>second<strong>: </strong>number<strong>): </strong>number<strong>{<br>    </strong>return first <strong>+ </strong>second<strong>;<br>  }<br>}<br><br></strong>@Injectable<strong>({<br>  </strong>providedIn<strong>: </strong>&#39;root&#39;<br><strong>})<br></strong>export class MySecondCalculator extends  MyCalculatorBase <strong>{<br>  </strong>calculate<strong>(</strong>first<strong>: </strong>number<strong>, </strong>second<strong>: </strong>number<strong>): </strong>number <strong>{<br>    </strong>return <strong>(</strong>first <strong>+ </strong>second<strong>) - </strong>10<strong>;<br>  }<br>}<br></strong></pre><p>Now, first, we need to create a dictionary object containing key-value object of the type string and MyCalculatorBase, as shown below:</p><pre>export const calculatorList<strong>: </strong>Map<strong>&lt; </strong>string<strong>, </strong>Type<strong>&lt;</strong>MyCalculatorBase<strong>&gt;&gt; = </strong>new Map<strong>&lt;</strong>string<strong>, </strong>Type<strong>&lt;</strong>MyCalculatorBase<strong>&gt;&gt;();<br></strong>calculatorList<strong>.</strong>set<strong>(</strong>&#39;MyFirstCalculator&#39;<strong>, </strong>MyFirstCalculator<strong>);<br></strong>calculatorList<strong>.</strong>set<strong>(</strong>&#39;MySecondCalculator&#39;<strong>, </strong>MySecondCalculator<strong>);</strong></pre><p>Now, in the component or any class where we need to get the MyCalculatorBase implementation dynamically, we will first need to inject the Injector class object. After that, we will get the implementation type of MyCalculatorBas based on string value from calculatorList object (that we created in the previous section above), after that, we will use <strong>get</strong> method of Injector class to get the registered implementation type. All this is shown in below code:</p><pre>@Component<strong>({<br>  </strong>selector<strong>: </strong>&#39;app-test&#39;<strong>,<br>  </strong>template<strong>: </strong>&#39;&lt;div&gt;hi&lt;/div&gt;&#39;<strong>,<br>  </strong>styles<strong>: []}<br>)<br></strong>export class TestComponent <strong>{<br>  </strong>constructor<strong>(</strong>private injector<strong>: </strong>Injector<strong>) {<br>  }<br><br>  </strong>getService<strong>(</strong>type<strong>: </strong>string<strong>): </strong>MyCalculatorBase <strong>{<br>    </strong>return this<strong>.</strong>injector<strong>.</strong>get<strong>(</strong>calculatorList<strong>.</strong>get<strong>(</strong>type<strong>));<br>  }<br>}</strong></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13cf4bad81a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular: Service injection in Angular]]></title>
            <link>https://medium.com/@danishjibbran_44045/service-injection-in-angular-6b8e409d3f46?source=rss-15e7e166e27c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b8e409d3f46</guid>
            <category><![CDATA[serviceinjectionmodule]]></category>
            <category><![CDATA[injection-service]]></category>
            <category><![CDATA[services]]></category>
            <category><![CDATA[serviceinjectioncomponent]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Danish Jibbran]]></dc:creator>
            <pubDate>Sun, 10 Apr 2022 04:49:35 GMT</pubDate>
            <atom:updated>2022-04-10T09:13:07.146Z</atom:updated>
            <content:encoded><![CDATA[<p>There are multiple different ways to inject Service/Classes in Angular at different levels e.g. application, module, component.</p><h3>1- Injecting service at project/application level:</h3><pre>@Injectable<strong>({<br>  </strong>providedIn<strong>: </strong>&#39;root&#39;<br><strong>})<br></strong>export class TestService <strong>{<br>  </strong>MyServiceMethodDoesNothing<strong>(): </strong>void <strong>{<br>  }<br>}</strong></pre><p>If we add the value “root” in provided in property then this service is injected at the application module and can be accessible/inject anywhere in the project.</p><h3>2- Injecting service at a module level:</h3><p>There are two methods of doing this:</p><h4>1- First method:</h4><p>In this method, we provided the name of the module in providedIn property:</p><pre>@Module<strong>({<br><br>})<br></strong>export class TestModule <strong>{<br>}<br><br></strong>@Injectable<strong>({<br>  </strong>providedIn<strong>: </strong>TestModule<br><strong>})<br></strong>export class TestService <strong>{<br>  </strong>MyServiceMethodDoesNothing<strong>(): </strong>void <strong>{<br>  }<br>}</strong></pre><h4>2- Second method:</h4><p>In this method, we don’t set any value to providedIn project in Injectable decorator, instead, we add the class name in the providers property array in Module decorator.</p><pre>@Injectable<strong>()<br></strong>export class TestService <strong>{<br>  </strong>MyServiceMethodDoesNothing<strong>(): </strong>void <strong>{<br>  }<br>}<br></strong>@Module<strong>()<br></strong>export class TestModule <strong>{<br>  </strong>providers<strong>: [</strong>TestService<strong>]<br>}</strong></pre><h3>3- Injecting service at a component level:</h3><p>To inject a service at the component level, instead, we add the class name in the providers property array in the Component decorator.</p><pre>@Component<strong>({<br>  </strong>selector<strong>: </strong>&#39;app-test&#39;<strong>,<br>  </strong>templateUrl<strong>: </strong>&#39;./test.component.html&#39;<strong>,<br>  </strong>styleUrls<strong>: [</strong>&#39;./test.component.scss&#39;<strong>],<br>  </strong>providers<strong>:[</strong>TestService<strong>]<br>})<br></strong>export class TestComponent <strong>{<br>  </strong>constructor<strong>(</strong>private testService<strong>: </strong>TestService<strong>){<br>  }<br>}</strong></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b8e409d3f46" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>