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('/');
})
Written by Chris Boden
Related protips
1 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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Angularjs
Authors
Related Tags
#angularjs
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#