【发布时间】:2016-01-15 22:00:25
【问题描述】:
我正在开发一个 AngularJS 1 和 Rails 4.2 应用程序。我正在使用 AngularRailsTemplates 加载我的 AngularJS 模板。
我目前在one single file 中拥有所有 AngularJS 控制器、配置、路由和工厂。我正在尝试将这些实体分隔到指定目录中(即见下文)。
| application.js
| controllers
| guest.js
| user.js
| factories
| lists.js
| templates
| home.html
| dashboard.html
我已将控制器和工厂文件分成模块。例如,在我的控制器目录中,我有两个控制器文件:
控制器/guest.js
angular.module('diction.controllers')
/* Guest Controller
* controller for static clientside for guest users
*
*/
.controller('GuestCtrl', ['$scope', '$stateParams', 'Auth', '$http', '$window',
// logic
}]);
控制器/user.js
angular.module('diction.controllers')
/* User Controller
* controller for users
*
*/
.controller('UserCtrl', ['$scope', '$stateParams', 'Auth', '$http', '$window',
// logic
}]);
我正在尝试将这些控制器模块加载到我的 application.js 文件中,它目前看起来像这样。
//= require angular-rails-templates
//= require_tree .
angular.module('diction', [
'ui.router',
'templates',
'diction.controllers'
])
/* Routing configuration for various 'states'
*
*/
.config(['$stateProvider', '$urlRouterProvider',
// Set state providers
function($stateProvider, $urlRouterProvider) {$stateProvider
// home
.state('home', {
url: '/home',
templateUrl: 'home.html',
controller: 'GuestCtrl',
})
}
]);
当我查看页面时,我收到“模块不可用”错误:
错误:$injector:nomod 模块不可用
模块“diction.controllers”不可用!你要么拼错 模块名称或忘记加载它。如果注册一个模块,请确保 您将依赖项指定为第二个参数。
非常感谢任何有用的提示。
【问题讨论】:
-
你的 index.html 呢?您是否包含具有依赖项的 js 文件?像这样...