2016-07-27 74 views
0

在我的index.html,我包括文件角NG-閒置不工作,未知提供商

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

和app.js

angular.module('app', [ uirouter, 
         routing, 
         angularResource, 
         localStorage, 
         home, 
         activity, 
         'chart.js', 
         'ngAnimate', 
         'rzModule', 
         'ui.bootstrap', 
         jsonService, 
         otherService, 
         customers, 
         'angularUtils.directives.dirPagination', 
         notifications, 
         'textAngular', 
         'ngSanitize', 
         'MassAutoComplete', 
         material, 
         countrySelect, 
         'ngIdle' 
         ]) 

和配置文件

.config(function(IdleProvider) { 
     IdleProvider.idle(5); 
     IdleProvider.timeout(5); 
    }) 
    .run(['Idle', function(Idle){ 
     // start watching when the app runs. also starts the Keepalive service by default. 
     Idle.watch(); 
    }]) 
    .controller('ctrl', function($scope) { 
     $scope.$on('IdleTimeout', function() { 
      let time = new Date(); 
      console.log('idle timeout at ', time); 
     }); 

     $scope.$on('IdleStart', function() { 
      let time = new Date(); 
      console.log('idle start at ', time); 
     }); 
    }) 

但瀏覽器總是說

angular.mi n.js:117Error:[$注射器:unpr] http://errors.angularjs.org/1.5.6/ $注射器/ unpr P0 = tProvider%20%3 C-%20噸%20%3 C-%20ctrl

未知提供商:tProvider < - 噸< - CTRL

回答

0

t在這種情況下,似乎是在「ctrl」控制器中對$scope的縮小引用。

如果您使用微小,你需要確保你使用Angular's DI annotation到處,即

.config(['IdleProvider', function(IdleProvider) { 
    // ... 
}]).controller('ctrl', ['$scope', function($scope) { 
    // ... 
}]) 
+0

抱歉確認晚了。謝謝@Phil –