[英]Unknown provider error when deploying Rails/AngularJS app to Heroku
I have a Rails/AngularJS app which works fine in local development environment. 我有一个Rails / AngularJS应用程序,在本地开发环境中工作正常。 However, when I deploy this app to Heroku the AngularJS doesn't work an returns this error:
但是,当我将此应用程序部署到Heroku时,AngularJS无法正常工作并返回此错误:
Unknown provider: eProvider <- e
I did a bit of research and it seems it has something to do with the precompiling and minification of the assets, but I don't know what to do to solve this. 我做了一些研究,似乎它与资产的预编译和缩小有关,但我不知道如何解决这个问题。 Any ideas?
有任何想法吗? Thanks!
谢谢!
This is how the controller looks: 这是控制器的外观:
function RemindersCtrl($scope, $http) {
$http.get('/reminders.json').success(function(data) {
$scope.reminders = data;
console.log(data);
});
}
And this is the code in the view: 这是视图中的代码:
%section.reminders
%div{"ng-controller" => "RemindersCtrl"}
%ul
%li{"ng-repeat" => "reminder in reminders"}
.title {{reminder.title}}
Update: I changed the controller to this, but with the same result: 更新:我将控制器更改为此,但结果相同:
var RemindersCtrl = function($scope, $http) {
$http.get('/reminders.json').success(function(data) {
$scope.reminders = data;
console.log(data);
});
}
RemindersCtrl.$inject = ['$scope','$http'];
According to AngularJS tutorial ( http://docs.angularjs.org/tutorial/step_05 ) you can either add this to the controller to prevent minification problems: 根据AngularJS教程( http://docs.angularjs.org/tutorial/step_05 ),您可以将其添加到控制器以防止缩小问题:
function RemindersCtrl($scope, $http) {
...
}
RemindersCtrl.$inject = ['$scope', '$http'];
or instead of defining a function like this: 或者不是像这样定义一个函数:
function RemindersCtrl($scope, $http) {
...
}
it should be done like this: 它应该这样做:
var RemindersCtrl = ['$scope', '$http', function($scope, $http) {
...
}];
Angular team (and also generally speaking) recommends that we do not pollute the global scope. Angular团队(一般而言)建议我们不要污染全球范围。
.controller method, .controller方法,
var myApp = angular.module('myApp',[]);
myApp.controller('GreetingCtrl', ['$scope', function($scope) {
$scope.greeting = 'Hola!';
}]);
worked fine for me. 对我来说很好。 This is documented on Angular Understanding Controllers documentation
这在Angular Understanding Controllers文档中有记录
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.