javascript - Angularjs:在 app.config 中注入(inject)服务,使其不受缩小的影响

标签 javascript angularjs

我正在尝试在 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/

相关文章:

javascript - 检查对象数组并忽略所有其他内容

javascript - Ajax 返回 HTML 子模板 - 插入 DIV 失败

java - 如何在 Restful Web 服务中从 Http Post 获取数组?

javascript - 来自不同 ng-repeat Angular js 的总和值

javascript - 将数据从工厂传输到 Controller

javascript - Jquery 与新的 Javascript 框架/库(Angular、Ember、React 等)

IE9 上基于 JavaScript 的 SVG 渐变操作

javascript - 在 Node.js 服务器和浏览器之间共享二进制缓冲区

javascript - node.js 将 http 响应写入流

javascript - 了解 $resource 工厂和 @ 前缀