Created
January 6, 2015 14:19
-
-
Save TRex22/cf1738f4f2dabb96a7e5 to your computer and use it in GitHub Desktop.
AngularJS Base Controller and page timeout query string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} | |
}); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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