关于路由配置角度js&的缩小问题打字稿最低安全 [英] Minification issue on route config angular js & typescript min safe
问题描述
我有一个包含多个js文件的包(由打字稿文件生成)
I have a bundle with several js files (generated by typescript files)
当我在包中使用缩小时,页面将失败。
When I use minification on the bundle, the page fails.
Chrome控制台上的错误:
The error on chrome console:
未捕获的错误:[$ injector: modulerr]由于以下原因而无法实例化模块
AppModule:错误:[$ injector:unpr]未知提供程序:n
Uncaught Error: [$injector:modulerr] Failed to instantiate module AppModule due to: Error: [$injector:unpr] Unknown provider: n
I将问题隔离到以下两个文件之一,即app.module和app.routes:
I isolated the problem to one of two files, the app.module and the app.routes as follows:
app.module:
app.module:
((): void=> {
var app = angular.module("AppModule", ['ngRoute', 'ngMessages', 'app.xxx.xxx.xxxModule', 'ngSanitize']);
app.config(AppModule.Routes.configureRoutes);
})();
应用路线:
/// <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和模块名称,我将它们消毒了)
(ignore the xxx and module names, I sanitized them)
我猜我看到的错误与$ routeProvider有关。注射有问题吗?我应该如何注入此最小安全值?
I am guessing the error I am seeing is regarding the $routeProvider. Is there problem in the inject? How should I inject this min safe?
推荐答案
您要求将$ routeProvider注入到不是min的静态函数中-安全。静态$ inject仅适用于Routes类构造函数。因此,您可以执行以下操作:
You are asking for $routeProvider to be injected in your static function which is not min-safe. static $inject applies to Routes class constructor only. So you can either do:
app.config(['$routeProvider', AppModule.Routes.configureRoutes])
或者如果您想充分利用Angular的DI:
Or if you want to make full use of Angular's DI:
export class Routes {
static $inject = ["$routeProvider"];
constructor(private $routeProvider: ng.route.IRouteProvider){
}
configureRoutes() {
this.$routeProvider.when("/xxx", { controller: "Uni.controllers.xxx", templateUrl: staticsDir + "/projects/xxx/xxx/xxx/xxx.html", controllerAs: "xxx" });
this.$routeProvider.when("/xxx2", { controller: "Uni.controllers.xxx2", templateUrl: staticsDir + "/projects/xxx2/xxx2/xxx2/xxx2.html", controllerAs: "xxx2" });
}
...
...
}
将其注册为提供者本身
即。 app.provider('myRoutes',Routes);
并将其注入到配置块中:
and inject it into the config block:
app.config(['myRoutes', function(myRoutes){
myRoutes.configureRoutes();
}]
(或其他类似的东西)
这篇关于关于路由配置角度js&的缩小问题打字稿最低安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!