sam*_*207 1 ruby-on-rails production-environment angularjs ruby-on-rails-4.1
我收到以下错误,我无法理解为什么.我尽力改变/检查错误的起源,但对我来说,一切似乎都是正确的.并且这个错误只发生在production,development它工作正常.
#error
Uncaught Error: [$injector:modulerr] Failed to instantiate module recipeApp due to:
Error: [$injector:nomod] Module 'recipeApp' 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.
#app.js
var mod = angular.module('recipeApp',[]);
#application.js
//= require jquery
//= require jquery_ujs
//= require pixel-admin.min
//= require app
#config/initializers/productio.rb
config.assets.compile = false
config.assets.precompile = ['*.js', '*.css']
config.assets.js_compressor = Uglifier.new(:mangle => false)
config.assets.js_compressor = :uglifier
#app/views/layout/application.html.erb
<body class="theme-default no-main-menu main-navbar-fixed" ng-app="recipeApp">
Run Code Online (Sandbox Code Playgroud)
当我通过萤火检查源,我可以看到recipeApp在这两个js和html
我正在使用
对于路由我正在使用ui.router,我怎么试图添加它,但仍然是相同的
#app/views/layouts/application.html.erb
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.js"></script>
<script src="//angular-ui.github.io/ui-router/release/angular-ui-router.js"></script>
Run Code Online (Sandbox Code Playgroud)
在我的
app/assets/javascripts/app.js
'use strict';
angular.module('recipeApp',["ui.router"]);
Run Code Online (Sandbox Code Playgroud)
小智 6
我也遇到了这个问题并在此处找到了解决方案:https://teamgaslight.com/blog/4-lessons-learned-doing-angular-on-rails.以为我会分享遇到这个问题的任何人,即使这个问题相当陈旧.
生产中的Rails会自动缩小混淆Angular的变量.
所以在config/environments/production.rb中,在添加此行之前end:
config.assets.js_compressor = Uglifier.new(mangle: false)
Run Code Online (Sandbox Code Playgroud)
您的应用需要使用Rails 4+