0

Writing a very simple angular js app to learn routes and partials. The problem is that my would just not load the partial template at all.

index.html

<!DOCTYPE html>
<html ng-app="website">
<head>
    <title>Hello World, AngularJS</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js"></script>
    <script type="text/javascript" src="../js/website.js"></script>
</head>
<body>
    <ul>
        <li><a href='/'>Home</a></li>
        <li><a href='/login'>Login</a></li>
        <li><a href='/about'>About</a></li>
    </ul>

    <ng-view></ng-view>
</body>
</html>

website.js

angular.module('website', ['ngRoute']).
config(function ($routeProvider, $locationProvider) {
    $routeProvider.
        when('/about', {templateUrl: 'partials/about.html'}).
        when('/login', {templateUrl: 'partials/login.html'}).
        otherwise({redirectTo:'/'});
    $locationProvider.html5Mode(true)
});

When I load index.html, it shows the links. When I click on one of the them, or go manually to #/about, it should load the contents of the template inside ng-view, but it doesn't.

The about.html and login.html are just two files with a single

tag in them with Hello World text. What am I missing? I was earlier not including angular-route.js, but fixing that didn't work.

My directory structure goes like this:

views
  --js
    --website.js
  --views
    --index.html
    --partials
      --about.html
      --login.html

The network says that it did GET about, but brings me back to index.html without anything in ng-view

6
  • So, where are these partials located? What does your browser console say? In the network panel, do you see a request loading trying to load the partial? What's the response? If index.html is at the root, how could it point to a file ../js/website.js? Have you at least checked that your js file was loaded and your angular application was started? Why are you learning angularJS with an obsolete version? Commented Oct 25, 2014 at 9:52
  • I might have been looking at an older tutorial. I updated the version to 1.2.25 Commented Oct 25, 2014 at 10:25
  • It seems that the js file was not loading at all. If I bring the contents inline to the html file, going to any route crashes the app! And I can now see the network to actually loading partials/about.html Commented Oct 25, 2014 at 10:36
  • How about changing href='/about' to href='#/about' (# is missing) ? Commented Oct 25, 2014 at 10:50
  • Thanks Lokesh, but no use.. Commented Oct 25, 2014 at 17:32

0

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.