Introduction
This article demonstrates MVC, using Angular Idle with UI Bootstrap. This article is useful to get a User Idle moment when logging in to the Application.
Angular Idle
Angular Idle can use an Angular module to detect and respond to idle users. We can almost maintain the session in the client side.
Follow the steps given below and we can use an Angular Idle in AngularJS in MVC.
- Create MVC project.
- Configure an Angular Idle
- Work with an Angular Idle.
Create MVC Project
Open Visual Studio 2015.

Go to New menu >Click New & project. Now, it will open New Project Window.

You can select ASP.NET Web Application on Framework 4.6. Enter the name of the project in Solution name textbox, followed by clicking OK button.

One more Window should be appearing. Select MVC template in this popup & click Ok button. Now, you can start.
Configure an Angular Idle
We will download the idle plug in from
- Ng-Idle
- UI-Bootstrap
Open the _Layout.cshtml and must refer the .js file from downloaded folder to this view page
- <script src="~/Plugin/angular/angular.min.js"></script>
- <script src="~/Plugin/angular-ui-router/release/angular-ui-router.min.js"></script>
- <script src="~/Plugin/angular-idle/angular-idle.js"></script>
- <script src="~/Plugin/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
Link My File
- <script src="~/App/App.module.js"></script>
- <script src="~/App/App.config.js"></script>
- <script src="~/App/CarController.js"></script>
- <script src="~/App/LoginConttroller.js"></script>
Angular Module
You will need to include the module as a dependency on your Application.
- var uiroute = angular
- .module('uiroute', ['ui.router', 'ngIdle', 'ui.bootstrap'])
Angular Config
You should also set your options, using the KeepaliveProvider, IdleProvider in your angular config file.
- uiroute.config(['KeepaliveProvider', 'IdleProvider', function(KeepaliveProvider, IdleProvider) {
- IdleProvider.idle(10);
- IdleProvider.timeout(10);
- KeepaliveProvider.interval(10);
- }]);
Angular Controller
You can set what action will be performed on the user idle times. Here, I will be shown a warning message & notified of the session logout .
- function closeModals() {
- if ($scope.warning) {
- $scope.warning.close();
- $scope.warning = null;
- }
- if ($scope.timedout) {
- $scope.timedout.close();
- $scope.timedout = null;
- }
- }
- $scope.$on('IdleStart', function() {
- closeModals();
- $scope.warning = $uibModal.open({
- templateUrl: 'warning-dialog.html',
- windowClass: 'modal-danger'
- });
- });
- $scope.$on('IdleEnd', function() {
- closeModals();
- });
- $scope.$on('IdleTimeout', function() {
- closeModals();
- $scope.timedout = $uibModal.open({
- templateUrl: 'timedout-dialog.html',
- windowClass: 'modal-danger'
- });
- });
Angular Run
After configuring the angular.idle.js, you must initiate the function in your angular Run function.
- uiroute.run(['Idle', function(Idle) {
- Idle.watch();
- }]);







Former memberPosted Jun 2, 2017, 7:32 AM
Not clear idea about these code "ne. IdleProvider.idle(10); IdleProvider.timeout(10); KeepaliveProvider.interval(10);"
Former memberPosted Jun 1, 2017, 7:13 AM
Who will call these function IdleStart & IdleEnd ? because these function has been register with on function.
Former memberPosted Jun 1, 2017, 7:12 AM
Please tell me what is the meaning of these below lne. IdleProvider.idle(10); IdleProvider.timeout(10); KeepaliveProvider.interval(10);