【发布时间】:2012-10-07 06:52:30
【问题描述】:
我在带有资产的 Ruby on Rails 3.2.8 项目中使用 AngularJS。
当我在我的开发机器上加载使用 AngularJS 的表单时,我没有问题。但是,当我在生产服务器上加载相同的表单时,我在 Javascript 控制台中收到此错误:
Error: Unknown provider: aProvider <- a
我已经将它追溯到我的咖啡脚本文件,我在该文件中设置了 AngularJS 以在表单中使用:
$ (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 功能。
问题是由于 Rails 资产编译和缩小造成的吗? 有没有办法解决这个问题并仍然使用咖啡脚本和 Rails 资产?
【问题讨论】:
-
我注意到,如果
$scope被重命名,它会中断。我建议通过app.controller('TimesheetCtrl', ['$scope', function($scope) {...}]);显式注入$scope(以与cofeescript 等效的方式)不过,可能还有其他这样的情况。
标签: ruby-on-rails ruby-on-rails-3 coffeescript angularjs