Reputation: 4501
I'm newbie with angujar.js and I want to develop a simple application which change content using some html files like this example
Is my config wrong? What else do I have to do?
index.html
<html ng-app="main">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
Some title
<div ng-view></div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js">
<script src="js/main.js"></script> <!-- app -->
</html>
main.js
var mymain = angular.module('main',[]);
mymain .config( function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'otherfile.html',
controller: 'F'
}).
otherwise({
redirectTo: '/'
});
});
mymain.controller('F', function($scope) {
alert("here");
});
otherfile.html
<span>Something else...</span>
Thanks in advance.
Edited
Do I have to have angular.js on a server(at least localhost) ? my code for route works here but not when I just open my file with a browser.
Upvotes: 0
Views: 186
Reputation: 4501
JB Nizet was right, I needed
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-resource.min.js"></script>
But I also needed
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-route.min.js"></script>
Upvotes: 0
Reputation: 692181
The router is not part of the core angular.js file. It's a separate module that must be declared in your main module dependencies. It's also in a separate JS file, that must be added to the index.html file, as explained in the documentation.
Upvotes: 1