我在我的 Angular 应用程序上使用 angular-xeditable。它在开发环境中工作正常,但在生产环境中,当所有 js 文件都被缩小时,我得到了这个错误:
Uncaught Error: [$injector:strictdi] http://errors.angularjs.org/1.3.5/$injector/strictdi?p0=function(n)
搜索我的代码,我发现 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>'
这里是缩小版本:
(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 方法中注释代码,它不会抛出异常。此方法用于配置 xeditable,如 documentation 中所述。 . 我无法弄清楚这种奇怪的行为,有什么方法可以查看 xeditable 是否已成功添加到 Angular 应用程序中,或者是否还有其他要检查的内容?
最佳答案
你必须注入(inject)依赖:
.run ( ['editableOptions', 'editableThemes', function(editableOptions, editableThemes)
类似controllers,services等(记得在run的之前加一个
。 ]
)
这是因为像 uglify 这样的最小化器改变了变量名。在上面的方式中,缩小代码将是:
.run( ['editableOptions', 'editableThemes', function(n,t){
n
和 t
将是对这些依赖项的引用。
关于javascript - Angularjs $ 注入(inject)器 :unpr in the run method after minification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27269954/