Last Updated: February 25, 2016
·
526
· cboden

ng Functional only controller

Recently I was writing an AngularJS logout controller. This controller was to only do one thing: change the state and redirect the user to /. The trouble was it was not being executed. As it turned out Angular requires some kind a template or templateURL for all routes. The solution was to set a template of a space:

angular.module('myapp.logout', [])

.config(function($routeProvider) {
    $routeProvider
    .when('/logout', {
        template: ' ', // <-- this is the important part
        controller: 'LogoutCtrl'
    }
})

.controller('LogoutCtrl', function($location) {
    // do logout stuff

    $location.path('/');
})

1 Response
Add your response

You could also check out https://github.com/angular-ui/ui-router.
It supports multiple views in one state and uses states instead of routes so your goal of not needing a template could be accomplished :)

over 1 year ago ·