AngularJS + Rails:未知提供者:e

时间:2015-04-12 19:21:25

标签: javascript angularjs ruby-on-rails-4 coffeescript

使用Rails 4和AngularJS转移到生产服务器后,我遇到了错误:[$injector:modulerr] Failed to instantiate module EcoApp due to: Error: [$injector:unpr] Unknown provider: e。 在阅读其他stackoverflow问题和角度文档之后,我想由于缩小而出现错误。不幸的是,我不知道角度是否足够好,经过多次尝试修复我的代码后,我决定在这里寻求帮助。

我的控制器文件(在CoffeeScript中):

angular.module('EcoApp')
.controller 'MyTripsCtrl', ($scope, $http) ->

  $http.get('/mytrips.json').success((data, status, headers, config) ->

    $scope.mytrips = data

    return

  ).error (data, status, headers, config) ->

    # log error

    return

  return


.controller 'NavbarIsActive', ($scope, $location) ->

  $scope.isActive = (select_path) ->

    select_path == $location.path()



  return


.controller 'NavbarIsActive2', [

  '$scope'

  '$location'

  ($scope, $location) ->

    $scope.isActive = (select_path) ->

      select_path == $location.path()

    return
]

正如你所看到的,我试图修复控制器NavbarIsActive,这在我看来是麻烦的原因,但没有结果。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:3)

是的,问题可能是缩小。如果一个minifier将你的代码装入这个:

.controller('Foobar', function (e) { .. })

然后Angular没有关于它需要注入什么的任何信息。这就是为什么存在替代注入语法的原因,您需要在任何地方使用它:

.controller 'Foobar', ['$scope', '$location', ($scope, $location) ->
    ..
]

指定每个依赖项两次:一次作为字符串,不会缩小,第二次作为实际函数签名中的任意变量名。