【发布时间】:2016-01-05 19:44:18
【问题描述】:
我有一个包含几个 js 文件的包(由 typescript 文件生成)
当我在捆绑包上使用缩小时,页面会失败。
chrome 控制台上的错误:
未捕获的错误:[$injector:modulerr] 无法实例化模块 AppModule 由于:错误:[$injector:unpr] 未知提供者:n
我将问题隔离到两个文件之一,app.module 和 app.routes,如下所示:
app.module:
((): void=> {
var app = angular.module("AppModule", ['ngRoute', 'ngMessages', 'app.xxx.xxx.xxxModule', 'ngSanitize']);
app.config(AppModule.Routes.configureRoutes);
})();
app.routes:
/// <reference path="../../../../../scripts/typings/angularjs/angular.d.ts" />
/// <reference path="../../../../../scripts/typings/angularjs/angular-route.d.ts" />
module AppModule {
declare var staticsDir: string;
export class Routes {
static $inject = ["$routeProvider"];
static configureRoutes($routeProvider: ng.route.IRouteProvider) {
$routeProvider.when("/xxx", { controller: "Uni.controllers.xxx", templateUrl: staticsDir + "/projects/xxx/xxx/xxx/xxx.html", controllerAs: "xxx" });
$routeProvider.when("/xxx2", { controller: "Uni.controllers.xxx2", templateUrl: staticsDir + "/projects/xxx2/xxx2/xxx2/xxx2.html", controllerAs: "xxx2" });
}
}
}
(忽略 xxx 和模块名称,我已对其进行了清理)
我猜我看到的错误是关于 $routeProvider 的。注入有问题吗?我应该如何安全地注射这个分钟?
【问题讨论】:
-
您在 Routes 上设置了 $inject,但没有在 configureRoutes 上设置。试试
app.config(['$routeProvider', AppModule.Routes.configureRoutes])
标签: angularjs typescript bundling-and-minification angularjs-ng-route