我使用angular JS制作一个rails应用程序。我的资产文件夹结构是assets path structure 的Gemfile
source 'https://rubygems.org'
gem 'rails', '4.2.4'
gem 'pg'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'unicorn'
group :development, :test do
gem 'byebug'
end
group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
end
gem 'devise'
gem 'haml-rails'
gem 'angular-rails-templates'
gem 'angularjs-rails'
gem 'angular-ui-router-rails'
gem 'sprockets', '2.12.3'
gem 'bower-rails'
gem 'active_model_serializers'
的application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require angular
//= require angular-ui-router
//= require angular-rails-templates
//= require angular-cookies
//= require restangular
//= require_tree ./controllers
//= require_tree ./templates
//= require_tree .
module.js
var app = angular.module("mofs", ['ui.router', 'ngCookies', 'templates', 'restangular']);
app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider){
$stateProvider.state('desktop', {
url: '/',
templateUrl: 'desktop.html',
controller: 'desktopCtrl'
});
$urlRouterProvider.otherwise('/');
}])
.run(['$http', '$cookies', function($http, $cookies)
{
$http.defaults.headers.common['X-XSRF-TOKEN'] = $cookies['XSRF-TOKEN'];
}]);
desktop.js
var desktopController = function($scope, Restangular)
{
Restangular.customGET('/current_user').then(function(current_user) {
$scope.currentUser = current_user;
console.log('done');
}, function (){
console.log('Ошибка при получении текущего пользователя (desktopController)');
})
}
angular.module("mofs").controller('desktopCtrl', ['$scope', 'RestAngular', desktopController]);
当我在控制台错误中加载根页面时出现:
模块' mofs'不可用!您要么错误拼写了模块名称 或者忘了加载它。如果注册模块,请确保指定 依赖关系作为第二个参数。
错误:[ng:areq] Argument' desktopCtrl'不是一个功能,未定义
如何正确包含到我的项目角度和任何依赖项?谢谢你,请原谅我的英文
答案 0 :(得分:0)
好像你实际上没有加载你的js文件。您应该通过HTML中的标记引用它们,以便能够使用它们。