0

在我的 index.html 中,我将文件包含为

<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.min.js:117Error: [$injector:unpr] http://errors.angularjs.org/1.5.6/ $injector/unpr?p0=tProvider%20%3C-%20t%20%3C-%20ctrl

未知提供者:tProvider <- t <- ctrl

4

1 回答 1

0

t在这种情况下,似乎是$scope“ctrl”控制器中的缩小参考。

如果您使用缩小,您需要确保在任何地方都使用Angular 的 DI 注释 ,即

.config(['IdleProvider', function(IdleProvider) {
    // ...
}]).controller('ctrl', ['$scope', function($scope) {
    // ...
}])
于 2016-07-27T05:50:11.390 回答