6

So I followed this guide: http://viralpatel.net/blogs/angularjs-routing-and-views-tutorial-with-example/

But when I try to change the view nothing happens, anybody a idea what I do wrong?

This is the code I got. Home.php:

<!DOCTYPE html>
<html ng-app="lax">
<head>
    <meta name="author" content="Koen Desmedt" />
    <meta name="description" content="CMS Belgium Lacrosse" />
    <meta name="keywords" content='Lacrosse, BLF, Belgium' />
    <meta name="googlebot" content="noarchive" />
    <link href="lib/bootstrap/css/bootstrap.css" rel="stylesheet">        
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
    <script src="lax.js"></script>
    <link href="css/style.css" rel="stylesheet">        
    <title>CMS Belgium Lacrosse</title>
</head>
<body>        
    <header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
        <div class="container">
            <div class="navbar-header">
                <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>                    
            </div>
            <nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
                <ul class="nav navbar-nav navbar-left">
                    <li>
                        <a href="#/home">
                            <span class="glyphicon glyphicon-home"></span> BLF
                        </a>
                    </li>
                    <li>
                        <a href="#/players">Players</a>
                    </li>
                    <li>
                        <a href="#/club">Club</a>                            
                    </li>
                    <li>
                        <a href="#/games">Games</a>
                    </li>                        
                </ul>             
            </nav>
        </div>
    </header>
    <div id='contentcontainer'>
        <div class='container' ng-view></div>
    </div>        
</body>
</html>

lax.js:

var lax = angular.module('lax', []);

lax.config(['$routeProvider',
function($routeProvider) {
    $routeProvider.
            when('/home', {
                templateUrl: 'views/news.php',
                controller: 'NewsController'
            }).
            when('/players', {
                templateUrl: 'views/players.php',
                controller: 'PlayersController'
            }).
            otherwise({
                redirectTo: '/home'
            });
}]);

lax.controller('NewsController', function($scope) {
$scope.message = 'This is Add new order screen';
});


lax.controller('PlayersController', function($scope) {
$scope.message = 'This is Show orders screen';
});

3 Answers 3

6

From angular 1.2.0, ngRoute has been moved to its own module. You have to load it separately and declare the dependency.

Update your html:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js"></script>

And Js:

var lax = angular.module('lax', ['ngRoute']);

For more information: http://docs.angularjs.org/guide/migration

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

Comments

1

Angular routes require the route module to be included as well. Here is the documentation that covers this.

So, I think you may be missing the:

<script src="angular-route.js"></script>

In the <head> of the page.

*Note: this module used to be part of Angular, but was moved out recently (1.2?). So, some tutorials are still assuming that $route is built-in.

1 Comment

Don't forget the closing </script> tag! Caught me out recently.
-1

Adding this would work :

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js"></script>

but it will not work without internet access when running for a first time ,Therefore you should ng-route dependency to your project and refer that in your html file

How to add ng-route dependency

1 Comment

Please either provide a solution with codes inserted into post, or just comment below the question. Thx.

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.