angular.module('MemberInduction').factory('DataAccessService', function ($http, ConfigService) {
var dataAccessService = {};
function writeToLocalStorage(data) {
localStorage.setItem('MI.ApplicationData', JSON.stringify(data));
reloadView();
}
function reloadView() {
window.location.href = '#/tab/home'
}
dataAccessService.load = function () {
var tempData = {};
var currentEnvironment = ConfigService.getEnvironment().environment;
var loadApplicationDataUrl = '';
if (currentEnvironment == 'dev') {
loadApplicationDataUrl = ConfigService.getEnvironment().urls.dev.baseUrl + ConfigService.getEnvironment().urls.dev.loadDataUrl;
} else {
loadApplicationDataUrl = ConfigService.getEnvironment().urls.live.baseUrl + ConfigService.getEnvironment().urls.live.loadDataUrl;
}
$http.get(loadApplicationDataUrl).success(function (data, status, headers, config) {
tempData = data;
writeToLocalStorage(data);
}).error(function (error) {
console.log('error handler of dataAccessService Load', error);
});
return tempData;
}
dataAccessService.resetLocalStorage = function () {
localStorage.setItem('MI.ApplicationData', null);
localStorage.setItem('MI.ApplicationFirstRun', false);
this.load();
};
dataAccessService.getInductionList = function () {
var dataFromlocalstorage = localStorage.getItem('MI.ApplicationData');
var appData = JSON.parse(dataFromlocalstorage);
return appData.Inductions;
};
dataAccessService.getInductionDetailsById = function (id) {
var inductionsObj = this.getInductionList();
var induction = null;
for (var inductionItem in inductionsObj) {
if (inductionsObj.hasOwnProperty(inductionItem)) {
if (inductionsObj[inductionItem].InductionId == id) {
induction = inductionsObj[inductionItem];
}
}
}
return induction;
};
dataAccessService.getGroupList = function () {
var dataFromlocalstorage = localStorage.getItem('MI.ApplicationData');
var groups = JSON.parse(dataFromlocalstorage).Groups;
return groups;
};
dataAccessService.getGroupDetailsById = function (id) {
var listOfGroups = this.getGroupList();
var selectedGroup = null;
for (var currentGroup in listOfGroups) {
if (listOfGroups.hasOwnProperty(currentGroup)) {
if (listOfGroups[currentGroup].GroupId == id) {
selectedGroup = listOfGroups[currentGroup];
}
}
}
return selectedGroup;
};
dataAccessService.getGeneralInformation = function () {
var data = JSON.parse(localStorage.getItem('MI.ApplicationData'));
var generalInformation = data.GeneralInformation;
return generalInformation;
};
return dataAccessService;
});
$stateProvider
.state('tabs', {
url: '/tab',
abstract: true,
templateUrl: 'tabs.html'
})
.state('tabs.home', {
resolve: {
DataAccessService: function (DataAccessService) {
return DataAccessService.load();
}
},
url: '/home',
views: {
'home-tab': {
templateUrl: 'assets/views/inductionList.html',
controller: 'InductionListCtrl'
}
}
})Hi Stephen,
No I have not witnessed something like this. Did you check the developers console on what errors are present when it’s not working?
A quick view of your source brings this line to my attention:
this.load();
I suspect your issue will be gone if you change that to:
dataAccessService.load();
I hope this helps you,
Regards
Sander
Hi
Thanks for this I'll try that change you suggested. Also I noticed that we're using appcache which seems to cause problems. I'm looking for ways to use appcache with an AngularJS/Ionic app.
Stephen
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/u7WtHaZ5lIo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.