Angularjs $injector:unpr 在缩小后的运行方法中

Angularjs $injector:unpr in the run method after minification

本文关键字:运行 方法 缩小 injector unpr Angularjs      更新时间:2023-09-26

我在我的Angular应用程序上使用Angular-xeditable。它在开发环境中工作正常,但在生产环境中,当所有 js 文件都缩小时,我收到此错误:

Uncaught Error: [$injector:strictdi] http://errors.angularjs.org/1.3.5/$injector/strictdi?p0=function(n)

搜索我的代码,我发现可编辑有问题。这里是咖啡脚本中的应用程序创建代码:

# create the angular app
angular.module 'dbManagerApp', ['xeditable', 'ngDraggable']

# set the theme for the xeditable
.run (editableOptions, editableThemes) ->
    # set the default theme
    editableOptions.theme = 'default'
    # override the ok button
    editableThemes['default'].submitTpl = '<div class="small primary btn"><input type="submit" value="Ok" /></div>'
    # override the cancel button
    editableThemes['default'].cancelTpl = '<div class="small warning btn" ng-click="$form.$cancel()"><a href="#">Cancel</a></div>'

这里是缩小版本:

(function(){angular.module("dbManagerApp",["xeditable","ngDraggable"]).run(function(n,t){if(!_.isUndefined(n||_.isUndefined(n.theme)))return n.theme="default",t["default"].submitTpl='<div class="small primary btn"><input type="submit" value="Ok" /><'/div>',t["default"].cancelTpl='<div class="small warning btn" ng-click="$form.$cancel()"><a href="#">Cancel<'/a><'/div>'})}).call(this);
//# sourceMappingURL=DbManagerApp.min.js.map

如果我在 run 方法中注释代码,它不会引发异常。此方法用于配置可编辑对象,如文档中所述。我无法弄清楚这种奇怪的行为,有没有办法查看可编辑项是否成功添加到角度应用程序中,或者是否有其他内容需要检查?

您必须注入依赖项:

.run ( ['editableOptions', 'editableThemes', function(editableOptions, editableThemes)

与控制器、服务等类似(请记住在运行)之前添加]

这是因为最小化器(如 uglify)更改变量名称。按照上述方式,缩小的代码将是:

.run( ['editableOptions', 'editableThemes', function(n,t){

nt将是对这些依赖项的引用。