Angular.js:未捕获的错误,没有模块:MyApp的 [英] Angular.js: Uncaught error, no module: myapp
问题描述
我尝试过引导的angular.js项目。这是我的index.html:
I'm trying too bootstrap an angular.js project. This is my index.html:
<!doctype html>
<html ng-app="myapp">
<head>
<meta charset="utf-8">
<base href="{% url 'app' %}" />
<title>Project</title>
</head>
<body>
<div ng-view>
<p>Loading...</p>
</div>
<script>
var url = function(path) { return '{{ STATIC_URL }}' + path };
</script>
<script src="{{ STATIC_URL }}js/jquery-1.10.1.js"></script>
<script src="{{ STATIC_URL }}js/angular.js"></script>
<script src="{{ STATIC_URL }}js/project/app.js"></script>
<script src="{{ STATIC_URL }}js/project/controllers.js"></script>
</body>
</html>
的网址应用
在头上简单地打印子路径,/应用程序,例如。这是我的app.js:
The url 'app'
on the head simply prints the subpath, /app, for example. This is my app.js:
'use strict';
var app = angular.module('myapp', []);
app.config(['$routeProvider', function($router) {
$router.when('/', {
templateUrl: url('partials/foo.html'),
controller: controllers.Foo
});
}]);
问题是,每次我尝试运行它,则会引发异常:未捕获的错误:没有模块:MyApp的
,这是几乎相同的方式的角种子工作。我搜索谷歌和计算器,但没有答案( 之一和的two )帮助了我。
The problem is that everytime I try to run it, an exception is raised: Uncaught Error: No module: myapp
, and this is almost the same way angular-seed works. I searched on Google and StackOverflow but none of the answers (one and two) helped me.
下面是一个小提琴了解我的错误(你应该打开浏览器的控制台来看看它)。这是怎么回事了?
Here's a fiddle about my error (you should open the browser's console to see it). What's going wrong?
推荐答案
你的脚本的顺序是非常重要的,尽量把它在你的&LT; HEAD&GT;
The order of your script is very important, try putting it in your <head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script>
var app = angular.module('myapp', []);
app.controller('Ctrl', function($scope){
$scope.variable = "Hello";
});
</script>
<body ng-app="myapp">
<div ng-controller="Ctrl">
<p>{{variable}}</p>
</div>
</body>
尝试在这里:
这篇关于Angular.js:未捕获的错误,没有模块:MyApp的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!