You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AngularJS v1.8.2升级后[$injector:modulerr]错误求助

解决AngularJS v1.8.2的[$injector:modulerr]错误

核心问题定位

你的loading指令依赖注入写法错误,AngularJS 1.8.x对依赖注入的校验更严格,未正确声明依赖会导致注入器初始化失败,触发[$injector:modulerr]。

修复步骤

1. 修正指令的依赖注入格式

原代码中loading指令的数组注入项缺失$http,需要把$http加入注入数组:

var app = angular.module('FormApp', ['ngTagsInput', "isteven-multi-select", "toastr", "angularUtils.directives.dirPagination", "treeGrid", "ngRoute"]);
app.controller('FormController', FormController);

FormController.$inject = ['$scope', '$http'];

// 修正后的loading指令
app.directive('loading', ['$http', function ($http) {
    return {
        restrict: 'A',
        link: function ($scope, elm, attrs) {
            $scope.isLoading = function () {
                return $http.pendingRequests.length > 0;
            };

            $scope.$watch($scope.isLoading, function (v) {
                if (v) {
                    elm.show();
                } else {
                    elm.hide();
                }
            });
        }
    };
}]);

注:去掉了原代码里的TypeScript类型标注elm: any,如果需要保留TS语法,确保项目已配置支持AngularJS+TS的编译环境,否则纯JS环境下会报错。

2. 验证依赖模块的兼容性与加载顺序

  • 确认所有依赖模块(如ngTagsInput、isteven-multi-select等)都支持AngularJS 1.8.x版本,部分旧模块可能存在兼容性问题,需升级对应依赖到兼容版本。
  • 确保页面中JS文件的加载顺序正确:先加载AngularJS核心库,再依次加载所有依赖模块的JS文件,最后加载你的业务代码。

3. 开启调试模式定位剩余问题

如果修正后仍报错,打开浏览器控制台,查看完整的错误堆栈信息,找到具体是哪个模块或注入项出问题。可以在AngularJS初始化前开启调试模式:

angular.module('FormApp').config(['$compileProvider', function ($compileProvider) {
    $compileProvider.debugInfoEnabled(true);
}]);

这会提供更详细的错误信息,帮助定位隐藏问题。

内容的提问来源于stack exchange,提问作者Omid Sotooni

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 10:40:45