Search code examples
angularjsng-idle

AngularJS: Unknown provider: $idleProvider


A lot of other people with similar problems but the resolutions don't seem applicable to my specific issue of this.

I am attempting to use the ngIdle (https://github.com/HackedByChinese/ng-idle) library but can't seem to get it to run without this error appearing - Uncaught Error: [$injector:modulerr] Failed to instantiate module myAuditModule due to: Error: [$injector:unpr] Unknown provider: $idleProvider

Here is my module code,

(function () {
    app = angular.module("myAuditModule", ['ui.bootstrap', 'ngRoute', 'ngCookies', 'ngDragDrop', 'ngIdle']);

    // configure the routes
    app.config(function ($routeProvider, $idleProvider, $keepaliveProvider) {

        $idleProvider.idleDuration(10 * 60); // 10 minutes idle
        $idleProvider.warningDuration(30); // 30 second warning
        $keepaliveProvider.interval(5 * 60); // 5 minute keep-alive ping

        $routeProvider

             //route for the logging in page
            .when('/', {
                templateUrl: 'Views/Login.html',
                controller: 'loginController'
            })

    });

    })();

The file is being included in my project and it is being shown as there in the developer console when the site is run -

   <script src="/Scripts/angular-idle.js"></script>

The only dependency is that you need to be using angular 1.2 or above, which I am.

Any ideas?


Solution

  • Replace $idleProvider to IdleProvider in app.config and try

      app.config(function ($routeProvider, IdleProvider, KeepaliveProvider) {
    
        IdleProvider.idleDuration(10 * 60); // 10 minutes idle
        IdleProvider.warningDuration(30); // 30 second warning
        KeepaliveProvider.interval(5 * 60); // 5 minute keep-alive ping
    
        .....
    });
    

    Also replace $keepaliveProvider to KeepaliveProvider