简体   繁体   English

从延迟加载的文件延迟加载时发生错误-angular.js

[英]Error when lazy-loading from a lazy-loaded file - angular.js

I'm using ocLazyLoad library to load on demand modules/files at angular.js. 我正在使用ocLazyLoad库在angular.js上按需加载模块/文件。 It works awesome and do what it needs to do. 它很棒,可以完成所需的工作。 However, I'm having one issue when trying to load files from a file that was previously loaded on demand. 但是, 尝试从以前按需加载的文件加载文件时遇到一个问题

the error is this: 错误是这样的:

 Error: jsLoader is not a function
 this.$get</filesLoader@https : //localhost/js/angular/includes/lazyload.js:245:1

And the piece of code I'm using (this is the file that was previously loaded on demand. It is executed correctly and actually it tries to load the file, but the above error is what I can see. No ajax is done to try to get the file): 和我正在使用的代码段(这是以前按需加载的文件。它已正确执行,实际上它尝试加载该文件,但是上面的错误是我可以看到的。没有ajax可以尝试获取文件):

angular.module("App").config(function($stateProvider, $controllerProvider, $ocLazyLoadProvider) {
    $ocLazyLoadProvider.config({
        debug: true,
        events: true
    });
    $stateProvider.state("controller", {
        url: "/:controller/:action",
        controller: function($rootScope, $state, $stateParams, $ocLazyLoad) {
            if (!$rootScope.controllers)
                $rootScope.controllers = {};

            if (!$rootScope.controllers[$stateParams.controller]) {
                $ocLazyLoad.load([{
                    files: [
                        "/js/angular/controller/" + $stateParams.controller + ".js"
                    ]
                }]).then(function() {
                    $rootScope.controllers[$stateParams.controller] = true;
                    $state.go($stateParams.controller + ( $stateParams.action ? ("." + $stateParams.action) : "" ));
                });
            }
            log($stateParams);
        }
    })
});

Has anyone had this issue? 有人遇到过这个问题吗?

The problem was the module was configured twice. 问题是模块配置了两次。

The fix: https://github.com/ocombe/ocLazyLoad/commit/c590579c9512e0dd3fae2c33c0aefc0bb0f7ca7e 修复程序: https : //github.com/ocombe/ocLazyLoad/commit/c590579c9512e0dd3fae2c33c0aefc0bb0f7ca7e

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM