0

I've been trying a ng-route example which works in AngularJS version 1.0.1 but not working in version 1.2.15. I did added the dependency angular-route.js but still getting uncaught object error. The following is my example. It consists of 4 files (index.html, page.html, chapter.html, and main.html).

If you comment out 1.2.15/angular.min.js, angular-route.js and .module('testNgRoute', ['ngRoute']) and uncomment 1.0.1/angular.min.js and .module('testNgRoute', []). It will work.

page.html contains only one line "This is page.html"

chapter.html contains only one line "This is chapter.html"

main.html contains only one line "This is main.html"

This is my index.html file

<!DOCTYPE html>
<html ng-app="testNgRoute">

    <title>Test ng-route</title>

    <body>
        <div>
            <h1>Test ng-route</h1>
            <div ng-view></div>
        </div>
    </body>

    <!--it works when I use this version of angularJS-->
    <!--<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>-->

    <!--it didn't work when I use this version of angularJS-->
    <!--  According to the documentation, I should include angular-route.js-->
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-route.js"><script>

    <script>
        angular
            //it works when I use v1.0.1 and without including any dependencies.
            //.module('testNgRoute', [])
            //it didn't work when I use v1.2.15 with the "ngRoute" dependencies
            .module('testNgRoute', ['ngRoute'])
            .config(['$routeProvider', function ($routeProvider) {

                "use strict";
                $routeProvider
                    .when('/page', {
                        templateUrl: "page.html" 
                    })
                    .when('/chapter', {
                        templateUrl: 'chapter.html'
                    })
                    .when('/', {
                        templateUrl: 'main.html'
                    });

            }]);
    </script>
</html>
Artem Petrosian
  • 2,964
  • 1
  • 22
  • 30
EuWern
  • 123
  • 7

1 Answers1

0

This is a rookie mistake. The angular-route.js script tag is not close properly. Thanks tasseKATT for spotting it.

False alarm. I've tested it and it is working correctly.

EuWern
  • 123
  • 7