Skip to content

Instantly share code, notes, and snippets.

@TRex22
Created January 6, 2015 14:19
Show Gist options
  • Save TRex22/cf1738f4f2dabb96a7e5 to your computer and use it in GitHub Desktop.
Save TRex22/cf1738f4f2dabb96a7e5 to your computer and use it in GitHub Desktop.
AngularJS Base Controller and page timeout query string
//ref: http://jasonwatmore.com/post/2014/03/25/AngularJS-A-better-way-to-implement-a-base-controller.aspx
//base.js
(function() {
var base = angular.module('base', []);
base.controller('BaseCtrl', function($scope, $location, $timeout, $route) {
var queryStr = $location.search();
if(queryStr.timeout){
var timeoutLengthSec = (queryStr.timeout) * (1000);
$timeout(function(){
$route.reload();
}, timeout);
}
});
})();
//home.js
(function() {
var home = angular.module('home', [
'titleService'
]);
home.config(function ($routeProvider) {
$routeProvider.
when('/home', {
templateUrl: 'home/home.tpl.html',
controller: 'HomeCtrl'
}).
otherwise({
redirectTo: '/home'
});
});
home.controller('HomeCtrl', function($scope, $log, titleService, $controller) {
titleService.setTitle('Home');
$controller('BaseCtrl', { $scope: $scope});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment