AngularJS + Rails:未知提供者:e
AngularJS + Rails: Unknown provider: e
使用 Rails 4 和 AngularJS 移动到生产服务器后,我遇到了错误:[$injector:modulerr] Failed to instantiate module EcoApp due to:
Error: [$injector:unpr] Unknown provider: e
。
在阅读了其他 Whosebug 问题和 angular 文档后,我想错误是由于缩小而出现的。不幸的是,我不知道 angular 是否足够好,在多次尝试修复我的代码后,我决定在这里寻求帮助。
我的控制器文件(在 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,我认为这是问题的根源,但没有结果。任何帮助将不胜感激!
是的,问题很可能是缩小。如果缩小器将您的代码乱码成这样:
.controller('Foobar', function (e) { .. })
then Angular 没有任何关于它究竟需要注入什么的信息。这就是存在替代注入语法的原因,您需要在任何地方使用它:
.controller 'Foobar', ['$scope', '$location', ($scope, $location) ->
..
]
您将每个依赖项指定两次:一次作为字符串,不会缩小,第二次作为实际函数签名中的任意变量名。
使用 Rails 4 和 AngularJS 移动到生产服务器后,我遇到了错误:[$injector:modulerr] Failed to instantiate module EcoApp due to:
Error: [$injector:unpr] Unknown provider: e
。
在阅读了其他 Whosebug 问题和 angular 文档后,我想错误是由于缩小而出现的。不幸的是,我不知道 angular 是否足够好,在多次尝试修复我的代码后,我决定在这里寻求帮助。
我的控制器文件(在 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,我认为这是问题的根源,但没有结果。任何帮助将不胜感激!
是的,问题很可能是缩小。如果缩小器将您的代码乱码成这样:
.controller('Foobar', function (e) { .. })
then Angular 没有任何关于它究竟需要注入什么的信息。这就是存在替代注入语法的原因,您需要在任何地方使用它:
.controller 'Foobar', ['$scope', '$location', ($scope, $location) ->
..
]
您将每个依赖项指定两次:一次作为字符串,不会缩小,第二次作为实际函数签名中的任意变量名。