错误:未知提供商:aProvider< - 一个 [英] Error: Unknown provider: aProvider <- a

查看:172
本文介绍了错误:未知提供商:aProvider< - 一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是与资产的Rails 3.2.8项目在Ruby AngularJS。

I'm using AngularJS in a Ruby on Rails 3.2.8 project with assets.

当我打开了我的形式,它是用我的机器上AngularJS我没有问题。然而,当我加载相同的表格我的生产服务器上我在JavaScript控制台中得到这个错误:

When I load up my form which is using AngularJS on my development machine I don't have a problem. However when I load the same form up on my production server I get this error in the Javascript console:

Error: Unknown provider: aProvider <- a

我已经跟踪它回到我的CoffeeScript文件,我设置为AngularJS的表单中使用:

I've tracked it back to my coffeescript file where I setup AngularJS for use within a form:

$ (event) ->
  $("#timesheet_description").autocomplete({source: '/autocomplete/work_descs'})

  # Create AngularJS module
  app = angular.module 'timesheetApp', []

  # Create a AngularJS controller
  app.controller "TimesheetCtrl", ($scope) ->
    $scope.costed_amount = 0
                                                                                                # Bind my module to the global variables so I can use it.
  angular.bootstrap document, ["timesheetApp"]  

如果我评论这一切出来的页面将加载没有错误,没有AngularJS能力。

If I comment all this out the page will load without errors and without AngularJS abilities.

时,由于Rails的资产编译和运行如下的问题?
有没有办法来解决这个问题,仍然使用的CoffeeScript和Rails资产?

Is the problem due to Rails assets compiling and minify? Is there a way to fix this and still use coffeescript and Rails assets?

推荐答案

AngularJS,使用您现在正在使用(称为pretotyping)的样式时,使用该函数的参数名称做依赖注入。所以,是的,它微小彻底打破这一点。

AngularJS, when using the style you're using right now (called pretotyping), uses the function argument names to do dependency injection. So yes, minification does break this completely.

解决方法是简单的,但。当你需要注射液(使用'$ XXX')变量任何情况下,做到这一点:

The fix is simple, though. In every case where you need injection (are using '$xxx') variables, do this:

app.controller "TimesheetCtrl", ['$scope', ($scope) ->
  $scope.costed_amount = 0
]

基本上,替换阵列中的所有函数定义。最后一个元素应该是函数定义本身,和第一的是你想注入的对象的 $名称

有一些(虽然不够清晰)上的信息的文档

There's some more (albeit not clear enough) info on the docs.

这篇关于错误:未知提供商:aProvider&LT; - 一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆