1

I have no idea why, but the JavaScript doesn't work.

The views don't get loaded when I click on the links

<html ng-app>
    <head>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
        <script type="text/javascript">
        var app = angular.module("app");
app.config(function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: 'views/default.html',
controller: 'default'
});
$routeProvider.when('/menu', {
templateUrl: 'views/menu.html',
controller: 'menu'
});
$routeProvider.otherwise({ redirectTo: '/' });
});
app.service( 'api', function($http)
{
this.get_id=function (js_data,success_fn) {
                $http({
                url: '/get_id',
                method: "POST",
                data: js_data,
                headers: {'Content-Type': 'application/json'}
            }).success(function (json) {var data=angular.fromJson(json);success_fn(data);});
            };

});
app.controller("default", function ($scope, $location) {
    $scope.test = "default";
});
app.controller("menu", function ($scope, api) {
    $scope.username = "UserName";
    $scope.get_id=function() {
        api.get_id(
                $scope.username,
                function (data)
                {alert(data);}
                    );
    }
});
        </script>
    </head>
    <body>
        <div >
            <a href="#/">home</a><br />
            <a href="#/menu">menu</a><br />
        </div>
        <div ng-view>
        </div>
    </body>
</html>
1
  • php tag should be changed to javascript tag. Commented Jan 8, 2014 at 22:40

1 Answer 1

2

The route provider is an external dependency in the 1.2 branch. You'll need to add:

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

You'll also need to add the ngRoute dependency:

ie. angular.module('ngViewExample', ['ngRoute'])

http://docs.angularjs.org/api/ngRoute.$routeProvider

Dependencies Requires the ngRoute module to be installed.

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

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.