Skip to content

Instantly share code, notes, and snippets.

@DevEarley
Last active October 3, 2018 15:19
Show Gist options
  • Save DevEarley/2f257934f5e76d145c1d6da50c7dcaf5 to your computer and use it in GitHub Desktop.
Save DevEarley/2f257934f5e76d145c1d6da50c7dcaf5 to your computer and use it in GitHub Desktop.
It's a JsonDataService
angular.module('someApp')
.service('JsonDataService', function () {
return {
init: function () {
var thisService = this;
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', './app/data/cm-ux-guide-data.json', true);
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
thisService.uxGuideData = JSON.parse(xobj.responseText)[0];
}
};
xobj.send(null);
},
uxGuideData: {},
getUxGuideData: function () {
return this.uxGuideData;
},
getNavigation: function () {
return this.uxGuideData["Navigation"];
},
getComponents: function () {
return this.uxGuideData["Components"];
},
getGuides: function () {
return this.uxGuideData["Guides"];
},
getNavigationByID: function (_NavigationID) {
return this.uxGuideData["Navigation"].Where(x => x.NavigationID == _NavigationID).toArray();
},
getComponentByID: function (_ComponentID) {
return this.uxGuideData["Components"].Where(x => x.ComponentID == _ComponentID).toArray();
},
getScriptByID: function (_ScriptID) {
return this.uxGuideData["Scripts"].Where(x => x.ScriptID == _ScriptID).toArray();
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment