Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
找不到AngularJs服务_Angularjs - Fatal编程技术网

找不到AngularJs服务

找不到AngularJs服务,angularjs,Angularjs,我试图将服务注入控制器,但未找到该服务错误: angular.js:13424 Error: [$injector:unpr] http://errors.angularjs.org/1.5.3/$injector/unpr?p0=<section data-ui-view="" class="view-container {{main.pageTransition.class}} ng-scope" data-ng-animate="1">copeProvider%20%3C-%2

我试图将服务注入控制器,但未找到该服务错误:

angular.js:13424 Error: [$injector:unpr] http://errors.angularjs.org/1.5.3/$injector/unpr?p0=<section data-ui-view="" class="view-container {{main.pageTransition.class}} ng-scope" data-ng-animate="1">copeProvider%20%3C-%20%24scope%20%3C-%20authenticationService
    at Error (native)
    at http://localhost:3000/bower_components/angular/angular.min.js:6:416
    at http://localhost:3000/bower_components/angular/angular.min.js:43:7
    at Object.d [as get] (http://localhost:3000/bower_components/angular/angular.min.js:40:270)
    at http://localhost:3000/bower_components/angular/angular.min.js:43:69
    at d (http://localhost:3000/bower_components/angular/angular.min.js:40:270)
    at e (http://localhost:3000/bower_components/angular/angular.min.js:41:1)
    at Object.instantiate (http://localhost:3000/bower_components/angular/angular.min.js:41:364)
    at Object.<anonymous> (http://localhost:3000/bower_components/angular/angular.min.js:42:184)
    at Object.invoke (http://localhost:3000/bower_components/angular/angular.min.js:41:295)
服务:

(function () {
    'use strict';

    angular.module('app.page')
        .service('authenticationService', ['$scope', '$window', authenticationService]);

    function authenticationService() {
        this.test = function()
        {
            alert('test');
        }
    }
})();

我这里做错了什么?

服务调用
['$scope','$window',authenticationService]
中的注入次数与服务函数的参数列表
()
不匹配

为了避免这样的错误,我建议您使用$inject():


服务调用
['$scope','$window',authenticationService]
中的注入数与服务函数
()
的参数列表不匹配

为了避免这样的错误,我建议您使用$inject():


为什么要将
$scope
注入到
authenticationService
中,以及如何在服务的功能中列出依赖项?在调用angular.module.controller之前,是否应该将
['$scope','$window',authenticationService]
更改为
[authenticationService]
?声明authCtrl。在函数声明之前,authCtrl应该是未定义的。为什么要将
$scope
注入
authenticationService
中,以及服务函数中的依赖项列表呢?在调用angular.module.controller之前,是否应该将
['$scope','$window',authenticationService]
更改为
[authenticationService]
?声明authCtrl。authCtrl应该在函数声明之前未定义。
(function () {
    'use strict';

    angular.module('app.page')
        .service('authenticationService', ['$scope', '$window', authenticationService]);

    function authenticationService() {
        this.test = function()
        {
            alert('test');
        }
    }
})();
(function () {
    'use strict';

    angular.module('app.page').service('authenticationService', authenticationService);

    authenticationService.$inject = [];

    function authenticationService() {
        this.test = function()
        {
            alert('test');
        }
    }
})();