Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
29
rated 0 times [  30] [ 1]  / answers: 1 / hits: 52162  / 11 Years ago, mon, june 24, 2013, 12:00:00

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>


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
});
}]);


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?


More From » angularjs

 Answers
5

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>


Try it here:



http://jsfiddle.net/vvfnN/2/


[#77440] Saturday, June 22, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrence

Total Points: 120
Total Questions: 115
Total Answers: 87

Location: England
Member since Fri, May 22, 2020
4 Years ago
terrence questions
Sat, Jun 5, 21, 00:00, 3 Years ago
Wed, Jun 17, 20, 00:00, 4 Years ago
;