[英]Angular — Failed to Instantiate Module
Im trying to figure out the client side of an application. 我试图找出应用程序的客户端。 Im using Angular, and when I try to load the page I get
我正在使用Angular,当我尝试加载页面时,我得到了
Uncaught Error: [$injector:modulerr] Failed to instantiate module Facebook due to:Error[$injector:nomod] Module 'Facebook' 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-rc.5/$injector/nomod?p0=Facebook
I've downloaded and included angular-route and angular-resource, they all compile before the application.js does, and I've moved my ng-app from html tag to body tag. 我已经下载并包含了angular-route和angular-resource,它们都在application.js之前进行了编译,并且我已经将ng-app从html标签移动到了body标签。
Any idea what I can do to get this working? 知道我该怎么做才能使它正常工作吗? It seems straightforward to get the module to work, but it refuses to.
使模块正常工作似乎很简单,但它拒绝这样做。
-application.html.erb -application.html.erb
<!DOCTYPE html>
<html>
<head>
<script src="/assets/angular/angular.js" type="text/javascript"></script>
<script src="/assets/angular/angular-resource.js" type="text/javascript"></script>
<script src="/assets/angular/angular-route.js" type="text/javascript"></script>
<%= javascript_include_tag "application" %>
<%= stylesheet_link_tag "application", media: "all" %>
<%= csrf_meta_tags %>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<script>
<![endif]-->
</head>
<body ng-app="Facebook">
<div ng-controller="MainCtrl">
<%= Time.now.strftime("%m/%d/%Y") %><br>
<%= Time.now.strftime("%I:%M:%S") %>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">Titration</a>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="span12">
<ng-view></ng-view>
</div>
</div>
<footer>
<p>© IHSDigital 2014</p>
</footer>
</div>
</div>
</body>
</html>
assets/angular/app.js 资产/角度/app.js
var app = angular.module("Facebook", [
"ngResource",
"Facebook.controllers",
"Facebook.services",
"ngRoute"
]);
app.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when("/facebook/index", { "views/facebook/index.html.erb", controller: "FacebookIndexCtrl" })
.when("/facebook/new", { templateUrl: "<%= asset_path('facebook/edit.html') %> ", controller: "FacebookEditCtrl" })
.when("/facebook/:id", { templateUrl: "<%= asset_path('facebook/show.html') %> ", controller: "FacebookShowCtrl" })
.when("/facebook/:id/edit", { templateUrl: "<%= asset_path('facebook/edit.html') %> ", controller: "FacebookEditCtrl" })
.otherwise({ redirectTo: "/facebook" });
});
app.config(function($httpProvider) {
$httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
});
application.js application.js
//
//= require angular
//= require angular-resource
//= require bootstrap
//= require ./angular/app
//= require_tree ./angular
I've tried switching the order files load, checked 50 times for spelling errors, and I'm out of ideas. 我尝试过切换订单文件的加载,检查了50次拼写错误,但我没有主意。
Your code 您的密码
javascript_include_tag "application"
is trying to load file application.js so your angular js file is not even loaded into your html page. 正在尝试加载文件application.js,因此您的js角文件甚至都没有加载到html页面中。
I dont know your project structure so i would use 我不知道你的项目结构,所以我会用
<script src="path/to/your/app.js" type="text/javascript"></script>
or 要么
javascript_include_tag "app"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.