Starkers
Starkers

Reputation: 10541

Debug angular routes

I have this code in my app:

angular.module('App',['ngRoute', 'ngResource']).config ($routeProvider)->
    $routeProvider.when('/app',
        templateUrl: 'app.html'
        controller: 'appController'
    )

.controller 'appController', ($scope)->
    console.log 'app controller called called'
    $scope.message = 'this is my app'

However, when I visit /app, nothing happens. I get no app controller called message. I get no error messages in the console. Nothing at all. I don't really know how I can debug this problem if I'm not given any information.

Is there a way to make angular more verbose so it gives me errors and warnings?

Upvotes: 3

Views: 7564

Answers (1)

Douglas Henrique
Douglas Henrique

Reputation: 329

Try visiting /#/app or setting $locationProvider.html5Mode(true). html5Mode is set to false by default and it expects a # symbol before the route.

EDIT

To debug the routes you could use Chrome's Tools (Ctrl+Shift+I -> Sources) and set breakpoints in angular-resource.js, but I don't think this is a good idea. Instead you can add:

$routeProvider.otherwise({
    redirectTo: "/somewhere"
});

If you get redirected then the correct route is not being called and so the controller is not being executed, therefore you have nothing to debug. You should check if htmlMode is set to false. If you don't get redirected then you should check if the files are correctly loaded and the app is correctly configured in your html file.

Upvotes: 2

Related Questions