<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xmlns:tt="http://teletype.in/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>@stacksjar</title><generator>teletype.in</generator><description><![CDATA[@stacksjar]]></description><link>https://teletype.in/@stacksjar?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=stacksjar</link><atom:link rel="self" type="application/rss+xml" href="https://teletype.in/rss/stacksjar?offset=0"></atom:link><atom:link rel="next" type="application/rss+xml" href="https://teletype.in/rss/stacksjar?offset=10"></atom:link><atom:link rel="search" type="application/opensearchdescription+xml" title="Teletype" href="https://teletype.in/opensearch.xml"></atom:link><pubDate>Fri, 01 May 2026 16:43:36 GMT</pubDate><lastBuildDate>Fri, 01 May 2026 16:43:36 GMT</lastBuildDate><item><guid isPermaLink="true">https://teletype.in/@stacksjar/FbAS8duSBa2</guid><link>https://teletype.in/@stacksjar/FbAS8duSBa2?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=stacksjar</link><comments>https://teletype.in/@stacksjar/FbAS8duSBa2?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=stacksjar#comments</comments><dc:creator>stacksjar</dc:creator><title>Progressive Web Application: Angular PWA</title><pubDate>Wed, 28 Sep 2022 20:39:28 GMT</pubDate><media:content medium="image" url="https://img2.teletype.in/files/18/d0/18d077b9-82b5-426c-9c46-bee6a24d865e.png"></media:content><description><![CDATA[<img src="https://img2.teletype.in/files/99/94/9994c3f0-63fe-436a-84dd-374bf137e7ff.jpeg"></img>In this article you will learn about how to make your angular app run even if there is no Internet (angular pwa offline). For this we are going to use Service Workers in Angular and apply caching method.]]></description><content:encoded><![CDATA[
  <h2 id="QInp">Introduction to Angular PWA</h2>
  <figure id="yRLE" class="m_column">
    <img src="https://img2.teletype.in/files/99/94/9994c3f0-63fe-436a-84dd-374bf137e7ff.jpeg" width="1200" />
  </figure>
  <p id="g7iS">In this article you will learn about how to make your angular app run even if there is no Internet (angular pwa offline). For this we are going to use Service Workers in Angular and apply caching method.</p>
  <p id="hU6x">To learn about Progressive Web Apps in angular read <a href="https://stacksjar.com/post/make-angular-run-in-offline-mode-pwa" target="_blank">Angular PWA</a></p>
  <p id="U46M">Service workers augment the traditional web deployment model and empower applications to deliver a user experience with the reliability and performance on par with natively-installed code. Adding a service worker to an Angular application is one of the steps for turning an application into a <a href="https://developers.google.com/web/progressive-web-apps/" target="_blank">Progressive Web App</a> also known as a PWA (angular pwa offline) and make angular run in offline mode,</p>
  <p id="n4tZ">So in short Service Workers is a script which intercepts all your network calls and cache the their responses in local cache system. You can cache API call responses and even your resource files too such as images etc.</p>
  <h2 id="yujG">Adding a service worker to your project</h2>
  <pre id="gvCG">ng add @angular/pwa --project *project-name*
</pre>
  <p id="W3Yq">By running this cli command the angular does following changes</p>
  <ol id="fhYt">
    <li id="LP7o">Adds the <code>@angular/service-worker</code> package to your project.</li>
    <li id="ogCI">Enables service worker build support in the CLI.</li>
    <li id="UMHE">Imports and registers the service worker in the app module.</li>
    <li id="bbiJ">Updates the <code>index.html</code> file: (Includes a link to add the <code>manifest.webmanifest</code> file, Adds meta tags for <code>theme-color</code>).</li>
    <li id="LDLX">Installs icon files to support the installed Progressive Web App (PWA).</li>
    <li id="ewTc">Creates the service worker configuration file called <code><a href="https://angular.io/guide/service-worker-config" target="_blank">ngsw-config.json</a></code>, which specifies the caching behaviors and other settings.</li>
  </ol>
  <p id="9eYW">The main file to set configuration of which resources are to be cached you have to check the <code><a href="https://angular.io/guide/service-worker-config" target="_blank">ngsw-config.json</a></code> file.</p>
  <pre id="ywKZ">{
  &quot;$schema&quot;: &quot;./node_modules/@angular/service-worker/config/schema.json&quot;,
  &quot;index&quot;: &quot;/index.html&quot;,
  &quot;assetGroups&quot;: [
    {
      &quot;name&quot;: &quot;app&quot;,
      &quot;installMode&quot;: &quot;prefetch&quot;,
      &quot;resources&quot;: {
        &quot;files&quot;: [
          &quot;/favicon.ico&quot;,
          &quot;/index.html&quot;,
          &quot;/manifest.webmanifest&quot;,
          &quot;/*.css&quot;,
          &quot;/*.js&quot;
        ]
      }
    }, {
      &quot;name&quot;: &quot;assets&quot;,
      &quot;installMode&quot;: &quot;lazy&quot;,
      &quot;updateMode&quot;: &quot;prefetch&quot;,
      &quot;resources&quot;: {
        &quot;files&quot;: [
          &quot;/assets/**&quot;,
          &quot;/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)&quot;
        ]
      }
    }
  ]
}
</pre>
  <p id="ezbp">As you can see in the above file angular by default adds some resources to this file which should be cached in the &quot;assetGroups&quot; object.</p>
  <p id="drSS">No we can go ahead and check service workers in action to do this first we have to create a Build of our angular project</p>
  <pre id="CG6U">//step1 build angular project
ng build --prod

//step2 server the build files using http-server
http-server dist/&lt;project-name&gt; -o

//step 2 Alternate method: Or go in your dist folder from your directory and run this command
http-server -o
</pre>
  <p id="yrTt">Make sure you have installed http-server on your system if not use this command to install it .</p>
  <pre id="yRFw">//install http-sever
npm i http-server
</pre>
  <p id="vmmS">Note: If you are not using HTTPS, the service worker will only be registered when accessing the app on localhost.</p>
  <p id="ESaj">Now once your app is completely loaded in the Browser go to your developer tools and in newtork tab switch to offline mode as showed in image below.</p>
  <figure id="moa7" class="m_custom">
    <img src="https://stacksjar.com/blogbackend/public/images/1606417397-1-bg.webp" width="600" />
  </figure>
  <p id="BOKc">Switching the offline method it switches off the internet access to your site in chrome. Now refresh your page and check network tab again you would see that the resources are loaded from the local cache and it will show as loaded from service worker check the image below, this verifies that your service workers are working as expected.</p>
  <figure id="2Fs0" class="m_custom">
    <img src="https://stacksjar.com/blogbackend/public/images/1606417599-1-bg.webp" width="600" />
  </figure>
  <p id="rGR5">Now to Cache the API calls made by your application you have to mention it in <code><a href="https://angular.io/guide/service-worker-config" target="_blank">ngsw-config.json</a></code> file by adding another array as &quot;dataGroups&quot; after the &quot;assetGroups&quot; array.</p>
  <pre id="VSzC">&quot;assetGroups&quot;: [{...}],
&quot;dataGroups&quot;: [
      {
        &quot;name&quot;: &quot;restapiexample dummuy API&quot;,
        &quot;urls&quot;: [&quot;https://reqres.in/api/users&quot;],
        &quot;cacheConfig&quot;: {
          &quot;strategy&quot;: &quot;freshness&quot;,
          &quot;maxSize&quot;: 20,
          &quot;maxAge&quot;: &quot;12h&quot;,
          &quot;timeout&quot;: &quot;5s&quot;
        }
      }
]

//name : Any name .
//urls : Array of API urls in string.
//strategy :  &#x27;freshness&#x27; | &#x27;performance&#x27; 
//maxSize : The maximum number of entries, or responses, in the cache.
//maxAge : &#x27;1d&#x27; | &#x27;1h&#x27; | &#x27;1m&#x27; | &#x27;1s&#x27; | &#x27;1u&#x27; 
//timeout : &#x27;1d&#x27; | &#x27;1h&#x27; | &#x27;1m&#x27; | &#x27;1s&#x27; | &#x27;1u&#x27; 
</pre>
  <p id="AhQn">In service worker Angular also provides a service to check whether there is a fresh version of application and you should refresh the application to replace the cached version stored in your browser cache or you can even notify the user like &quot;fresh content available please refresh&quot;.</p>
  <pre id="yrj4">//import service
import { SwUpdate } from &#x27;@angular/service-worker&#x27;;

//inject in constructor and use 
constructor(updates: SwUpdate) {
    updates.available.subscribe(event =&gt; {
      console.log(&#x27;current version is&#x27;, event.current);
      console.log(&#x27;available version is&#x27;, event.available);
      console.log(&#x27;old version was&#x27;, event.previous);
      console.log(&#x27;new version is&#x27;, event.current); 
    });
  } 
</pre>
  <p id="uhG2">Note: Make sure the API or network calls you make user <strong>Https </strong>because Service Workers doesn&#x27;t work on <strong>Http</strong> protocols.</p>
  <p id="bwvg">Some of the most common questions related to Angular Service Workers</p>
  <h2 id="aT0V">Angular pwa not working offline</h2>
  <p id="chuX">Some of the developers face problem of angular pwa not working offline to fix this firstly you have to check your build files inside dist folder and look for ngsw-manifest.json, sw-register.b73048fe3d9f8a1e7ae5.bundle.js and worker-basic.min.js files. If you don&#x27;t find these files it means your service worker was not registered correctly. Secondly you have to check your Network Environment, service workers doesn&#x27;t work in http it requires https so if you don&#x27;t have a SSL certificate your service worker won&#x27;t work.</p>
  <h2 id="VJKx">Angular service worker not caching API</h2>
  <p id="sXYv">When you add angular pwa to your application you get a <code><a href="https://angular.io/guide/service-worker-config" target="_blank">ngsw-config.json</a></code> file it consists config for caching the static resources in &quot;assetsGroups&quot; Object. To enable caching of Api in angular service worker you have to set &quot;dataGroups&quot; Object inside <code><a href="https://angular.io/guide/service-worker-config" target="_blank">ngsw-config.json</a></code> file.</p>
  <pre id="f68M">&quot;dataGroups&quot;: [
      {
        &quot;name&quot;: &quot;restapiexample dummuy API&quot;,
        &quot;urls&quot;: [&quot;https://reqres.in/api/users&quot;],
        &quot;cacheConfig&quot;: {
          &quot;strategy&quot;: &quot;freshness&quot;,
          &quot;maxSize&quot;: 20,
          &quot;maxAge&quot;: &quot;12h&quot;,
          &quot;timeout&quot;: &quot;5s&quot;
        }
      }
]
</pre>
  <h2 id="vgp8">How to create a new project in angular offline?</h2>
  <p id="63JF">To create new project in angular offline mode use --skip-install followed by ng new --projectName command.</p>
  <pre id="S8Jq">ng new yourProject --skip-install
</pre>
  <h2 id="aZeD">Angular offline storage</h2>
  <p id="TupG">When you are in offline mode no requests will be made to the database as API calls need internet connection to work. You can although cache the API requests using angular service worker which will efficiently deliver the results stored in cache when there is no Internet Connection. Also if you want to save some data temporarily you could still use the LocalStorage. LocalStorage is an default HTML API which stores data locally in your Browser.</p>
  <h2 id="fZgH">Angular service worker cache API</h2>
  <p id="jkC3">To enable caching of Api in angular service worker you have to set &quot;dataGroups&quot; Object inside <code><a href="https://angular.io/guide/service-worker-config" target="_blank">ngsw-config.json</a></code> file.</p>
  <pre id="Q02o">&quot;dataGroups&quot;: [
      {
        &quot;name&quot;: &quot;restapiexample dummuy API&quot;,
        &quot;urls&quot;: [&quot;https://reqres.in/api/users&quot;],
        &quot;cacheConfig&quot;: {
          &quot;strategy&quot;: &quot;freshness&quot;,
          &quot;maxSize&quot;: 20,
          &quot;maxAge&quot;: &quot;12h&quot;,
          &quot;timeout&quot;: &quot;5s&quot;
        }
      }
]
</pre>
  <h2 id="BaiL">Ngsw-worker js not found</h2>
  <p id="5Z2N">If your Ngsw-worker js file is not generate on prod build make sure you serviceWorker is set to true in angular-cli.json.</p>
  <pre id="Obl1">&quot;build&quot;: {
    &quot;configurations&quot;: {
        &quot;production&quot;: {
            &quot;serviceWorker&quot;: true
        }
    }
}
</pre>
  <h2 id="QAff">Angular service worker update cache</h2>
  <p id="ysAd">If you want data to be updated as soon as there&#x27;s new data available you can set cacheConfig strategy to freshness in <code><a href="https://angular.io/guide/service-worker-config" target="_blank">ngsw-config.json</a></code> file.</p>
  <pre id="SYi9">&quot;dataGroups&quot;: [
      {
        &quot;name&quot;: &quot;restapiexample dummuy API&quot;,
        &quot;urls&quot;: [&quot;https://reqres.in/api/users&quot;],
        &quot;cacheConfig&quot;: {
          &quot;strategy&quot;: &quot;freshness&quot;,
          &quot;maxSize&quot;: 20,
          &quot;maxAge&quot;: &quot;12h&quot;,
          &quot;timeout&quot;: &quot;5s&quot;
        }
      }
]
</pre>
  <h2 id="wnLT">Angular service worker exclude url</h2>
  <p id="3uCV">To exclude url in service worker you just have to skip that url from urls array in &quot;dataGroups&quot; of <code><a href="https://angular.io/guide/service-worker-config" target="_blank">ngsw-config.json</a></code> file. You should only specify the urls which you want to be cached.</p>
  <p id="OttS">Hope you find this post useful.</p>
  <p id="vL6A">Read the original Article about Progressive Web Apps in angular <a href="https://stacksjar.com/post/make-angular-run-in-offline-mode-pwa" target="_blank">Angular PWA</a></p>

]]></content:encoded></item><item><guid isPermaLink="true">https://teletype.in/@stacksjar/7END9OcMkZf</guid><link>https://teletype.in/@stacksjar/7END9OcMkZf?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=stacksjar</link><comments>https://teletype.in/@stacksjar/7END9OcMkZf?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=stacksjar#comments</comments><dc:creator>stacksjar</dc:creator><title>Use of Currency Pipe in Angular</title><pubDate>Wed, 21 Sep 2022 17:31:02 GMT</pubDate><media:content medium="image" url="https://img3.teletype.in/files/2d/9f/2d9f1d1d-fc2c-4383-8923-930c360d59b4.png"></media:content><description><![CDATA[<img src="https://stacksjar.com/blogbackend/public/images/1605635988-1-bg.webp"></img>In this blog post, we’ll learn about Currency Pipe in Angular.]]></description><content:encoded><![CDATA[
  <figure id="CA1H" class="m_custom">
    <img src="https://stacksjar.com/blogbackend/public/images/1605635988-1-bg.webp" width="700" />
    <figcaption>https://stacksjar.com/post/use-of-currency-pipe-in-angular (currency pipe angular)</figcaption>
  </figure>
  <h2 id="bvSi">How to use Currency Pipe in Angular</h2>
  <p id="qPok">In this blog post, we’ll learn about <strong>Currency Pipe</strong> in <strong>Angular.</strong></p>
  <p id="0411">We all know how much we struggle for making a number format precise when we have to show currency based on the country and their respective currencies.</p>
  <p id="QZyL">We have to add an appropriate currency icon and show commas separated values with 2 decimal fixed values. We have to run the Pricing number through certain functions and write code to add commas and currency icons.</p>
  <p id="JsmW"><strong>Angular </strong>here makes it handy by providing a Built in Mechanism that we all know is Pipes which is used for formatting data. Angular has a bunch of pipes currency pipe angular is one of them. <strong>Angular </strong>has a Currency Pipe built in we just have to use it according to our needs.</p>
  <h4 id="souw"><a href="https://angular.io/api/common/CurrencyPipe" target="_blank"><strong>CurrencyPipe</strong></a> is an <strong>API</strong> provided by angular. It is part of the angular <a href="https://angular.io/api/common/CommonModule" target="_blank"><strong>CommonModule</strong></a>.</h4>
  <p id="Slsm">It transforms a number to a currency string, according to locale rules that determine sizing, separator, decimal-point characters, and other locale-specific configurations.</p>
  <h2 id="L0K5">Syntax of Currency pipe Angular :</h2>
  <pre id="Hg51">{{ value_expression | currency [ : currencyCode [ : display [ : digitsInfo [ : locale ] ] ] ] }}
</pre>
  <p id="xiob">Example:</p>
  <p id="8CDh"><strong>app.component.ts</strong></p>
  <pre id="g0dO">price: number = 10050.4521;
</pre>
  <p id="PqR9"><strong>app.component.html</strong></p>
  <pre id="XcB3">{{ price | currency }} //output $10,050.45
</pre>
  <p id="k1bo">This is the basic method of using a currency pipe, the default Currency code for this pipe is &#x27;USD&#x27;. But this default is Deprecated from Angular version 9. But you can still set it as default by providing as providers for this pipe as follows:</p>
  <pre id="DPJb">{provide: DEFAULT_CURRENCY_CODE, useValue: &#x27;USD&#x27;}
</pre>
  <p id="RlO9">There are other examples as well which you could use according to your needs and configurations</p>
  <p id="vnHv"><strong>app.component.ts</strong></p>
  <pre id="Welm">a: number = 0.259;
b: number = 1.3495;
</pre>
  <p id="wyBZ"><strong>app.component.html</strong></p>
  <pre id="DeEz">&lt;p&gt;A: {{a | currency}}&lt;/p&gt;
&lt;!--output &#x27;$0.26&#x27;--&gt;

&lt;p&gt;A: {{a | currency:&#x27;CAD&#x27;}}&lt;/p&gt;
&lt;!--output &#x27;CA$0.26&#x27;--&gt;

&lt;p&gt;A: {{a | currency:&#x27;CAD&#x27;:&#x27;code&#x27;}}&lt;/p&gt;
&lt;!--output &#x27;CAD0.26&#x27;--&gt;

&lt;p&gt;B: {{b | currency:&#x27;CAD&#x27;:&#x27;symbol&#x27;:&#x27;4.2-2&#x27;}}&lt;/p&gt;
&lt;!--output &#x27;CA$0,001.35&#x27;--&gt;

&lt;p&gt;B: {{b | currency:&#x27;CAD&#x27;:&#x27;symbol-narrow&#x27;:&#x27;4.2-2&#x27;}}&lt;/p&gt;
&lt;!--output &#x27;$0,001.35&#x27;--&gt;

&lt;p&gt;B: {{b | currency:&#x27;CAD&#x27;:&#x27;symbol&#x27;:&#x27;4.2-2&#x27;:&#x27;fr&#x27;}}&lt;/p&gt;
&lt;!--output &#x27;0 001,35 CA$&#x27;--&gt;

&lt;p&gt;B: {{b | currency:&#x27;CLP&#x27;}}&lt;/p&gt;
&lt;!--output &#x27;CLP1&#x27; because CLP has no cents--&gt;
</pre>
  <h2 id="gbny">Angular currency pipe without symbol</h2>
  <p id="eSrf">If you want to show numbers in currency format without the symbol, or you want to use a currency pipe without a symbol use the below format:</p>
  <pre id="57Kc">&lt;p&gt; {{ b | currency:&#x27;USD&#x27;:&#x27;&#x27; }} &lt;/p&gt;

&lt;!--output 1.35 --&gt;
</pre>
  <h2 id="FW1c">Angular currency pipe INR</h2>
  <p id="iyiB">If you want to show currency in Indian rupees, Use angular currency pipe INR.</p>
  <pre id="zNvQ">&lt;p&gt; {{ b | currency:&#x27;INR&#x27; }} &lt;/p&gt;
&lt;!--output ₹1.35 --&gt;﻿
</pre>
  <h2 id="TSpD">Angular currency pipe without decimal</h2>
  <p id="MnWc">Use angular currency pipe without a decimal point with this format</p>
  <pre id="rVxi">&lt;p&gt; {{ b | currency:&#x27;USD&#x27;:true:&#x27;1.0-0&#x27; }} &lt;/p&gt;
&lt;!--output $1 --&gt;
</pre>
  <p id="QZHm">If you want to show currency without decimal points, using an angular currency pipe without decimal points won&#x27;t work you should use the number pipe instead, if you need just numbers use this below format.</p>
  <pre id="RZb2">&lt;p&gt; {{ b | number:&#x27;1.0-0&#x27; }} &lt;/p&gt;
&lt;!--output 1 --&gt;
</pre>
  <h2 id="kSp7">Angular currency pipe in component</h2>
  <p id="dwkC">Below is the code to use the angular currency pipe in the component. You have to import it and pass it into with providers inject it via the constructor and it&#x27;s ready to use.</p>
  <p id="0Hxi"><strong>app.module.ts</strong></p>
  <pre id="5H6p">import { NgModule } from &#x27;@angular/core&#x27;;
import { BrowserModule } from &#x27;@angular/platform-browser&#x27;;
import { CurrencyPipe  } from &#x27;@angular/common&#x27;;
import { AppComponent } from &#x27;./app.component&#x27;;

@NgModule({
  imports:      [ BrowserModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ],
  providers:    [ CurrencyPipe ]
})

export class AppModule { }
</pre>
  <p id="rP4Z"><strong>app.component.ts</strong></p>
  <pre id="Eljv">import { Component } from &#x27;@angular/core&#x27;;
import { CurrencyPipe } from &#x27;@angular/common&#x27;;

@Component({
  selector: &#x27;my-app&#x27;,
  templateUrl: &#x27;./app.component.html&#x27;,
  styleUrls: [ &#x27;./app.component.css&#x27; ]
})

export class AppComponent  {
  priceString:String = &#x27;100&#x27;;
  price:any;

  constructor(private currencyPipe:CurrencyPipe){
    this.price = this.currencyPipe.transform(this.priceString);
  }
  
}
</pre>
  <p id="PQwY"><strong>app.component.html</strong></p>
  <pre id="vSSo">&lt;p&gt; This is angular currency pipe used in component {{price}} &lt;/p&gt;

&lt;!--output﻿ This is angular currency pipe used in component $100.00 --&gt;
﻿
</pre>
  <h2 id="AWmc">List of currencies with output for Angular Currency Pipe</h2>
  <p id="tpuu">Here’s the list of currencies for the output of this input</p>
  <p id="okQC"><code>{{number1 |currency:item.key:&#x27;symbol&#x27;}}.</code></p>
  <p id="QO4U">and <code>number1 = 100</code></p>
  <h3 id="O5T8">Angular Currency Pipe FAQ</h3>
  <h2 id="aFwv">What is Currency Pipe in Angular</h2>
  <p id="WX8c">Angular Currency Pipe is one of the built in pipes in Angular used to format currency value according to given country code, currency, decimal, locale information.</p>
  <h3 id="r2jK">What is Angular Currency Pipe Syntax?</h3>
  <p id="5nAj"><code>{{ value_expression | currency [ :currencyCode [ :display [ : digitsInfo [ : locale ] ]]] }}</code></p>
  <ul id="zwSg">
    <li id="ttRh"><strong>value_expression:</strong> the number to be formatted as a currency.</li>
    <li id="uPUE"><strong>currency:</strong> A pipe keyword that is used with a pipe operator.</li>
    <li id="g7jf"><strong>currencyCode:</strong> The currency code, i.e USD for US dollar or EUR for the Euro.</li>
    <li id="WdPr"><strong>digitsInfo :</strong> Format: {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}.</li>
    <li id="Q0eP"><strong>locale :</strong> A locale code for the locale format rules to use. When not supplied, uses the value of LOCALE_ID, which is en-US by default.</li>
  </ul>
  <h2 id="TV7b"><strong>How to add CurrencyPipe in TypeScript File</strong></h2>
  <p id="ZKK2">Below is the code to use the angular currency pipe in component. You have to import it and pass it into with providers inject it via constructor and its ready to use.</p>
  <p id="5X3p"><strong>app.module.ts</strong></p>
  <pre id="jZUk">import { NgModule } from &#x27;@angular/core&#x27;;
import { BrowserModule } from &#x27;@angular/platform-browser&#x27;;
import { CurrencyPipe  } from &#x27;@angular/common&#x27;;
import { AppComponent } from &#x27;./app.component&#x27;;

@NgModule({
  imports:      [ BrowserModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ],
  providers:    [ CurrencyPipe ]
})

export class AppModule { }
</pre>
  <p id="8ilK"><strong>app.component.ts</strong></p>
  <pre id="VKjN">import { Component } from &#x27;@angular/core&#x27;;
import { CurrencyPipe } from &#x27;@angular/common&#x27;;

@Component({
  selector: &#x27;my-app&#x27;,
  templateUrl: &#x27;./app.component.html&#x27;,
  styleUrls: [ &#x27;./app.component.css&#x27; ]
})

export class AppComponent  {
  priceString:String = &#x27;100&#x27;;
  price:any;

  constructor(private currencyPipe:CurrencyPipe){
    this.price = this.currencyPipe.transform(this.priceString);
  }
  
}
</pre>
  <h2 id="mUzG">Angular format Currency</h2>
  <pre id="APsW">&lt;p&gt;A: {{a | currency}}&lt;/p&gt;
</pre>
  <h2 id="gEPY">What is the default value of symbol display while using the currencypipe</h2>
  <pre id="pwtc">{{ price | currency }} //output $10,050.45
</pre>
  <p id="MQCp">This is the basic method of using a currency pipe, the default Currency code for this pipe is &#x27;USD&#x27;. But this default is Deprecated from Angular version 9. But you can still set it as default by providing as providers for this pipe as follows:</p>
  <pre id="pBDV">{provide: DEFAULT_CURRENCY_CODE, useValue: &#x27;USD&#x27;}
</pre>
  <h2 id="sNSm">How do you use currency pipe in input type?</h2>
  <p id="DgS8"><code>&lt;input type=&quot;text&quot; value=&quot;&quot;&gt;</code></p>
  <h3 id="PPHY">Angular Currency Pipe with Currency Code Syntax</h3>
  <p id="Ab17"><code>{{number1 | currency:&#x27;CAD&#x27;}}</code></p>
  <h3 id="h0KS">Angular Currency Pipe Remove Decimal(No Decimal)</h3>
  <p id="0oQ0"><code>{{number1 | currency:&#x27;USD&#x27;:&#x27;symbol&#x27;:&#x27;4.0&#x27;}}</code></p>
  <p id="bCAe">This is useful when you don’t want to display cents in amount. (Angular Currency pipe no cents)</p>
  <h3 id="HnrK">Angular Currency Pipe INR</h3>
  <p id="qYYf"><code>{{number1 | currency:&#x27;INR&#x27;:&#x27;symbol&#x27;}}</code></p>
  <p id="JGpE"><strong>Output: </strong>₹1,980.00</p>
  <p id="gKvP">Hope you have now understood the use of angular currency pipe</p>
  <p id="pxg2">Below are some code snippets related to Currency Pipe</p>
  <h2 id="RH78"><a href="https://stacksjar.com/snippets/currency-pipe-in-typescript" target="_blank">Currency pipe in Typescript</a></h2>
  <h2 id="P0Xk"><a href="https://stacksjar.com/snippets/indian-currency-pipe-in-angular" target="_blank">Indian currency pipe in Angular 6</a></h2>
  <h2 id="bqqG"><a href="https://stacksjar.com/snippets/currency-pipe-in-angular-without-symbol" target="_blank">Currency pipe in Angular</a></h2>
  <h2 id="OXIF"><a href="https://stacksjar.com/snippets/currency-pipe-in-angular-without-symbol" target="_blank">Currency pipe angular without symbol</a></h2>
  <p id="hpt7"><strong>Happy Coding!</strong></p>

]]></content:encoded></item></channel></rss>