我正在尝试在 app.config 中注入(inject)服务,如 Inject service in app.config 所示。然而,缩小会破坏应用程序。如何克服这个问题?
这不适用于缩小:
app.config(['$routeProvider',function ($routeProvider) {
$routeProvider
.when('/',
{
templateUrl: "partials/editor.html",
controller: "AppCtrl",
resolve: {
//Following method doesn't work with minification
data: function (dbService) {
return dbService.getData();
}
}
})
}]);
最佳答案
您需要使用 Angular 文档中所述的内联数组注释来注入(inject)它。
Careful: If you plan to minify your code, your service names will get renamed and break your app.
如文档中所述,
someModule.controller('MyController', ['$scope', 'greeter', function($scope, greeter) {
// ...
}]);
就你而言,
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/',
{
templateUrl: "partials/editor.html",
controller: "AppCtrl",
resolve: {
//Following method doesn't work with minification
data: ['dbService', function (dbService) {
return dbService.getData();
}]
}
})
}]);
从这里引用:Angularjs: Inject Service in app.config such that to safeguard against minification
关于javascript - Angularjs:在 app.config 中注入(inject)服务,使其不受缩小的影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33919620/