27Dec

⚡ Angular — Protect your unsaved data

Have you ever filled a form and mistakenly closed that tab or went back without completing the process and lost all those data? Prevent your users from experiencing the same.

Angular provides CanDeactivate route guard, which prevent navigating from one route to another, unless the given condition becomes truthy.

Imagine a simple dashboard, having a form which helps User registration.

1

If the form is filled or half filled (dirty) and if the Admin navigates to some other route mistakenly, then the form entries will get lost and that Admin have to re-enter all the entries again to complete the registration.

In-order to prevent that, we can show a confirm popup, where Admin states that he is navigating with his knowledge, if not the navigation will be prevented.

As said earlier, we can achieve this using CanDeactivate route guard.

Create a service which implements CanDeactivate, which asks for canDeactivate() method which in-turn takes an argument component as the component which we want to implement CanDeactivate. And register your service in the provides array in the respective module.

 

angular canDeactivate router

CanDeactivate implementation3Simple bootstrap form

 

@ViewChild(‘userForm’) userForm: NgForm; inside the component, through which we can be able to check whether the form is dirty (value entered) or not.

Here, if the Admin navigates from the route which has filled form to another, confirm pop-up will be appeared.

3Preview

In this way, we can prevent our user from losing their data.

In this example anyway we have only two inputs. It won’t be much tedious to re-enter the data again. Consider a form with 10+ or 20+ inputs. It will be very painful if that is the situation. Hope this helps 💖

Related

Avoid These 14 Subject Line To Get A Prospect

A blog which highlights on email subject line that most people after reading gives up from opening t...

Read More >

Webinar - The process of version migration from older versions of Navision to NAV 2013 R2

Please watch LIVE RECORDING Video of the webinar session below which took place on 5th Jun...

Read More >

WScript Sleep- Exercise Desktop Remainder

Introduction - WScript.Sleep WScript.Sleep         ...

Read More >

Upcoming Webinar - Plugging for Cloud, Right or Wrong?

Plugging for the Cloud, Right or Wrong?Cloud computing continues to be one of the most advertising t...

Read More >

How to build a client side Repeater Using jQuery and ASP.NET AJAX

jTemplate is a template engine plug-in for jQuery and is commonly used to display tabular data ...

Read More >

NAV – Connecting Microsoft Dynamics CRM customized entities

This blog is intended to see how Microsoft Dynamics NAV (here onwards NAV) can be connected to exter...

Read More >

Authorize access to VSTS REST APIs with OAuth 2.0

Visual Studio Team Services uses the OAuth 2.0 protocol to authorize your app for a user and generat...

Read More >

To recover the space occupied by TFS 2010, after deleting the artifacts.

When you delete the team project or project artifacts from TFS 2010, the TFS collection database won...

Read More >

CxO Roundtable at C-SOaP- SUMMIT 2013

   img{ display:block; } #outlook a{ padding:0; } body{ width:100% !importa...

Read More >

Setup Jenkins for VSO with TFVC

Jenkins provides an easy-to-use Continuous Integration method, making it easier for developers to in...

Read More >

Share

Post a Comment

  • Recent
  • Popular
  • Tag
Tags
Monthly Archive
Subscribe
Name

Contact Us
  • *
  • *