0

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.

6
  • Do you have any errors in console? Commented Dec 21, 2013 at 23:24
  • Are you asking us to review the code or solve a problem with it? Commented Dec 21, 2013 at 23:28
  • @SeanDoe how can I see those errors? Commented Dec 21, 2013 at 23:29
  • 1
    It depends of browser you use, but predominantly pressing F12 shows debug console Commented Dec 21, 2013 at 23:30
  • @DavinTryon I'm just asking for help, at least a hint to make it works. Commented Dec 21, 2013 at 23:30

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I added angular-resource.min.js but it does not still work, what else should I to?
You must add the 'ngResource' module in the dependencies of your app, as explained in the documentation. Read it.
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.
Yes, I don't think using the route api on file URLs would work.
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.