角错误:添加依赖性给出$注射器:UNPR未知提供商



我决定在我的应用程序中添加nginfinitis Croll插件。因此,我叫该文件:

<script type="text/javascript" src="{!! asset('/js/ng-infinite-scroll.min.js') !!}"></script>

在我的events.js文件中,我启动了这样的模块:

(function(window) {
    // Define the `app` module
    var app = angular.module('stayhyper', ['infinite-scroll']); 
    app.controller('eventController', ['$scope', '$rootScope', '$http', 'myService',
        function($scope, $rootScope, $http, myService) {
        } // end of main function
    ]); // end of controller
})(window);

然后我收到以下错误:

错误:$注射器:UNPR未知提供商

未知提供商:MyServiceProvider&lt; - MyService&lt; - EventController

myService(这是在已加载在标题中的单独的JS文件中):

app.service('myService', function() {
            this.URL= function() {
               // set the main route of the site
                var subhost = "/"
                if (window.location.host == "localhost") {
                    subhost = "/myapp/public/"
                }
                window.urlRoot = window.location.origin + subhost;//main root of the site
                return window.urlRoot;
            }
            this.APIURL= function() {
               // set the main route of the site
                var subhost = "/api/"
                if (window.location.host == "localhost") {
                    subhost = "/myapp/public/api/"
                }
                window.urlRoot = window.location.origin + subhost;//main root of the site
                return window.urlRoot;
            }

    });

您最初需要加载event.js,然后再加载mainapp.js,然后最初只能创建模块,还请确保您已在HTML中添加了infinite-scroll

中的引用

这样,订单将是

 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ngInfiniteScroll/1.2.2/ng-infinite-scroll.js"></script>
 <script type="text/javascript" src="mainapp.js"></script>
 <script type="text/javascript" src="event.js"></script>

还确保您不再次调用模块。

最新更新