I"m very new to Angular and I'm having problems configuring IdleProvider and KeepaliveProviders. Please understand the question: I've already configured those two providers correctly and my idle timeout is working. What I'm looking for is how to provide values to those providers by reading such values from a properties file. I've been able to read values from a properties file but I'm unable to pass them to the providers in my .config() method.
I'm using angular 1.4.3 (pls don't ask me to upgrade - I just joined a project where they are using this.
Here's my config method in route.js
define(['app'], function(app) {
'use strict';
return app
.config(function($stateProvider, $urlRouterProvider, $httpProvider, KeepaliveProvider, IdleProvider) {
console.log("Idle timer is here")
IdleProvider.idle(5); //Rather than hardcoding, I want to pass from a property file
IdleProvider.timeout(5); //Rather than hardcoding, I want to pass from a property file.
KeepaliveProvider.interval(10); //Same here - pass from a property file
I have a Service class where I read my property file and set the result in $sessionStorage but I'm not able to inject the sessionStograge into the .config(..) method above because you can only inject constants and providers into .config(..). Any help would be appreciated!
auth.getRedirectUrls2 = function() {
console.log("getRedirectUrls2 has been caled!!");
var promise = $http.get("resources/sessiontimeout.properties")
.then(function(response) {
console.log("In getRedirectUrl2 response is: ", response.data);
console.log("Is the damn data in the session or not: ", $sessionStorage.redirectprops);
$sessionStorage.redirectprops = response.data;
return response.data;
})
.catch(function(response) {
console.error('Gists error', response.status, response.data);
})
.finally(function() {
console.log("In getRedirectUrls2 - Finally, all is done!!");
});
$sessionStorage.redirectpromise = promise;
console.log("The promise is: ", promise);
console.log("The promise from session is: ", $sessionStorage.redirectpromise);
return promise;
};
=======Edited with follow-up questions ====
I have the following project structure but don't know where to create the provider. webapp/static/app/js
- controllers (all controllers here)
- directivers (all directives here)
- services (all services here)
Also, can I create tryConstant.layouts.idleTime inside the provider constructor like this?
- layout.idleTime=xyz
- layout.intervalTime=abc
Where do I inject $sessionStorage or the service in the provider?