Javascript 赫罗库+;轨道&x2B;角度[$喷油器:nomod]
我的angular.js/rails应用程序在本地工作时遇到问题,导致Heroku上的js崩溃 为了允许本地测试,我下载了所有angular.js文件并将其放置在供应商目录中。我没有使用任何gems,只是将angular文件放在资产管道中,以便单个控制器coffeescript文件可以使用angular库 这是我的app.js:Javascript 赫罗库+;轨道&x2B;角度[$喷油器:nomod],javascript,ruby-on-rails,ruby,angularjs,heroku,Javascript,Ruby On Rails,Ruby,Angularjs,Heroku,我的angular.js/rails应用程序在本地工作时遇到问题,导致Heroku上的js崩溃 为了允许本地测试,我下载了所有angular.js文件并将其放置在供应商目录中。我没有使用任何gems,只是将angular文件放在资产管道中,以便单个控制器coffeescript文件可以使用angular库 这是我的app.js: angular.module('generosity', ['ngRoute', 'templates']) .config(['$routeProvider', '$
angular.module('generosity', ['ngRoute', 'templates'])
.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {
$routeProvider.
when('/', {
templateUrl: "users-form.html",
controller: 'UsersController'
}).
// when('/phones/:phoneId', {
// templateUrl: 'partials/phone-detail.html',
// controller: 'PhoneDetailCtrl'
// }).
otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
}])
.controller('UsersController' ['$scope', '$http', '$rootScope', function($scope, $http, $rootScope) {
var self = this;
self.username;
self.realName;
self.password;
self.availableHours; //How should this be styled?
self.currentCity;
self.currentLocation;
self.recipient; //Should probably be renamed
$scope.errCode = 0;
self.addUser = function() {
var errCode;
$http.post('users/add', {username: self.username, password: self.password}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
var errCode = data.errCode;
self.retrieveErrCode(errCode);
// console.log("HYA" + self.errCode);
if(errCode == -2) {
alert("Error: This username already exists.");
}
else if(errCode == -3) {
alert("Error: The username is empty, too long, or has invalid characters.");
}
else if(errCode == -4) {
alert("Error: The password is empty, too long, or has invalid characters.");
}
else {
alert("User created.");
}
console.log(errCode);
$rootScope.errCode = data.errCode;
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
alert("Error.");
});
console.log(self.username);
return $scope.errCode;
}
self.retrieveErrCode = function(code) {
$scope.err = code;
console.log("here");
};
self.createDummyUser = function() {
self.username = "LordChristopher";
self.realName = "Lord Christopher";
self.password = "Team 61C";
self.availableHours = "6 to 11 pm";
self.currentCity = "Berkeley";
self.currentLocation = "Nowhere";
self.recipient = "He whose name shall not be spoken";
};
// self.login = function(name, pw) {
// };
// self.logout = function() {
// };
}])
.controller('SessionController', ['$scope', '$http', '$rootScope', function($scope, $http, $rootScope) {
var self = this;
self.userId;
self.username;
self.login = function(username, password) {
$http.post('login', {username: username, password: password}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
alert("Connected");
console.log("connected");
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log("error");
alert("Error.");
});
}
}])
.directive('navbar', function() {
return {
restrict: 'E',
templateUrl: "navbar.html"
};
})
.directive('usersForm', function() {
return {
restrict: 'E',
scope: {
},
templateUrl: "users-form.html"
};
})
.directive('loginForm', function() {
return {
restrict: 'E',
scope: {
},
templateUrl: "login-form.html"
};
})
.directive('usersTests', function() {
return {
restrict: 'E',
scope: {
},
templateUrl: "users-tests.html"
};
})
// .directive('directiveA', function() {
// return {
// restrict: 'A',
// scope: {
// name: '@',
// hobby: '@'
// },
// templateUrl: "example-module.html"
// };
// }) //Only put a semi-colon on the last directory of the module
.directive('css1', function() {
return {
restrict: 'C',
link: function(scope, element, attrs) {
element.css("width", 400),
element.css("font-style", "oblique");
element.css("color", "green");
element.css("font-size", "30px");
}
};
})
.directive('testStatus', function() { //You do not need to account for the cases for which the rating is not a number.
return {
restrict: 'C',
scope: {
message: '@'
},
link: function(scope, element, attrs) { //Note that this is a function of scope, NOT $scope!!
if(scope.message.search("PASS") > 0) {
element.css("color", "green");
}
else if(scope.message.search("FAIL") > 0) {
element.css("color", "red");
}
else {
element.css("color", "blue");
}
}
};
})
它使用Rails s在本地运行良好。然而,尽管我尽了最大的努力(config/assets/production.rb中的所有“service static assets:true”,以及一些自动缩小js文件以用于生产的附加功能),heroku仍返回以下stacktrace:
Uncaught Error: [$injector:modulerr] Failed to instantiate module generosity due to:
Error: [$injector:nomod] Module 'generosity' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.3.0/$injector/nomod?p0=generosity
at https://still-plains-1604.herokuapp.com/assets/application-b623e3dc11cb731dd5e417203ceb10d1.js:5:20793
at https://still-plains-1604.herokuapp.com/assets/application-b623e3dc11cb731dd5e417203ceb10d1.js:5:28971
at e (https://still-plains-1604.herokuapp.com/assets/application-b623e3dc11cb731dd5e417203ceb10d1.js:5:28543)
at https://still-plains-1604.herokuapp.com/assets/application-b623e3dc11cb731dd5e417203ceb10d1.js:5:28855
at https://still-plains-1604.herokuapp.com/assets/application-b623e3dc11cb731dd5e417203ceb10d1.js:6:4062
at o (https://still-plains-1604.herokuapp.com/assets/application-b623e3dc11cb731dd5e417203ceb10d1.js:5:21178)
at h (https://still-plains-1604.herokuapp.com/assets/application-b623e3dc11cb731dd5e417203ceb10d1.js:6:3840)
at _e (https://still-plains-1604.herokuapp.com/assets/application-b623e3dc11cb731dd5e417203ceb10d1.js:6:5485)
at Q.s (https://still-plains-1604.herokuapp.com/assets/application-b623e3dc11cb731dd5e417203ceb10d1.js:5:26814)
at Q (https://still-plains-1604.herokuapp.com/assets/application-b623e3dc11cb731dd5e417203ceb10d1.js:5:27124)
http://errors.angularjs.org/1.3.0/$injector/modulerr?p0=generosity&p1=Error…com%2Fassets%2Fapplication-b623e3dc11cb731dd5e417203ceb10d1.js%3A5%3A27124) application-b623e3dc11cb731dd5e417203ceb10d1.js:6
为清楚起见,“慷慨”是应用程序本身的名称,在app.js中定义
为什么我定义的模块在生产中找不到,而在本地却找不到
该应用程序可以在网站上找到,任何关于这个问题的帮助都是天赐良机。你的消息来源有几个问题
data-ng-app
标记谢谢你的提醒!这些实际上是来自其他stackoverflow问题的挥之不去的“修复”尝试。我担心angular-route.js没有正确导入,所以我尝试将其设置为手动标记——但是它作为rails管道中的一项资产导入的效果很好。我更新了heroku网站以反映这一点--删除这两个问题仍然没有解决空白显示的问题。。。