Angularjs $ injector:缩小后的run方法中的unpr

Dar*_*one 3 javascript asp.net-mvc minify angularjs

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

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

搜索我的代码,我发现xeditable出了问题.这里是coffescript中的应用创建代码:

# 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>'
Run Code Online (Sandbox Code Playgroud)

这里是缩小版:

(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 Code Online (Sandbox Code Playgroud)

如果我在run方法中注释代码,它不会抛出异常.此方法用于配置文档中描述的xeditable .我无法弄清楚这种奇怪的行为,有没有办法看看xeditable是否成功添加到角度应用程序或是否有其他东西要检查?

Mic*_*ael 6

你必须注入依赖项:

.run ( ['editableOptions', 'editableThemes', function(editableOptions, editableThemes)
Run Code Online (Sandbox Code Playgroud)

与控制器,服务等类似(记得在运行]之前添加一个)).

这是因为诸如uglify之类的最小化器改变了变量名称.在上面的方式,缩小的代码将是:

.run( ['editableOptions', 'editableThemes', function(n,t){
Run Code Online (Sandbox Code Playgroud)

而且nt将这些依赖引用.