<?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: Devam Mahajan</title>
    <description>The latest articles on DEV Community by Devam Mahajan (@devam_mahajan).</description>
    <link>https://dev.to/devam_mahajan</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%2F172674%2Fcfa93429-75fc-4665-a92a-9a319a3c2636.jpg</url>
      <title>DEV Community: Devam Mahajan</title>
      <link>https://dev.to/devam_mahajan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devam_mahajan"/>
    <language>en</language>
    <item>
      <title>Check User is ONLINE/OFFLINE using Snackbar in Angular in a minute!</title>
      <dc:creator>Devam Mahajan</dc:creator>
      <pubDate>Sun, 02 Jun 2019 07:26:47 +0000</pubDate>
      <link>https://dev.to/devam_mahajan/check-user-is-online-offline-using-snackbar-in-angular-in-a-minute-3eh3</link>
      <guid>https://dev.to/devam_mahajan/check-user-is-online-offline-using-snackbar-in-angular-in-a-minute-3eh3</guid>
      <description>&lt;p&gt;Here is a small and easy Angular application to check if user is connected to Internet or not with use of Angular material!&lt;/p&gt;

&lt;p&gt;First of all you have to install a packaged called ng-connection-service. Lets see how do we do that.&lt;/p&gt;

&lt;p&gt;Create new Angular application using CLI&lt;/p&gt;

&lt;p&gt;&lt;em&gt;ng new Online&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Install the ng-connection-service package inside the application from the CLI using:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;npm install ng-connection-service - save&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once if you done this process please check your package.json whether it is added or not&lt;/p&gt;

&lt;p&gt;you should see like below,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4ZRli_0h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2Aow_7wLeRjTiu5B8ODCyCCg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4ZRli_0h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2Aow_7wLeRjTiu5B8ODCyCCg.png" alt="angular-online"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;now, time to install Angular Material into your project using CLI&lt;/p&gt;

&lt;p&gt;&lt;em&gt;install - save @angular/material @angular/cdk @angular/animations&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;now, import it in app.component.ts like below:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;import {MatSnackBar,MatSnackBarConfig,MatSnackBarHorizontalPosition,MatSnackBarVerticalPosition} from '@angular/material';&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let us finally inject the service inside the component. If you are familiar with service, you'd know that to inject a service, we go to the constructor of the component class and inject it as follows:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;constructor(private connectionService: ConnectionService, public snackbar: MatSnackBar){&lt;br&gt;
});&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;now the time for write logic of checking the internet connectivity. See the code below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dUzK-Mxo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AXtHPSpnIsXiFPupJ-QZH5g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dUzK-Mxo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AXtHPSpnIsXiFPupJ-QZH5g.png" alt="angular-online"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;app.component.tsFinal result look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YJvD9939--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AbJdwRa36GPDwbkfOK2czww.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YJvD9939--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AbJdwRa36GPDwbkfOK2czww.gif" alt="angular-online"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;final outputhere you can see whenever I turned off my wifi connection Snackbar pop up in bottom and show OFFLINE Status.&lt;/p&gt;

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