"use strict" angular.module('goApp.data', []) .service('Data', [ '$rootScope', '$http', function($rootScope, $http) { var data = []; var data_loaded = false; $http({ method: 'GET', url: 'scripts/data.json' }).success(function(json_data) { data = json_data; data_loaded = true; $rootScope.$broadcast('data:loaded', data); console.log('> Loaded data.json'); }); this.get = function() { return data; } this.getPageData = function(link){ if (data_loaded) { var page_data = ""; for (var i = 0; i < data.navigation.length; i++) { if(data.navigation[i].link == "submenu"){ for (var a = 0; a < data.navigation[i].submenu.length; a++) { if(data.navigation[i].submenu[a].link == "submenu"){ for (var b = 0; b < data.navigation[i].submenu[a].submenu.length; b++) { if(data.navigation[i].submenu[a].submenu[b].link == link){ page_data = data.navigation[i].submenu[a].submenu[b]; } } } else if(data.navigation[i].submenu[a].link == link){ page_data = data.navigation[i].submenu[a] } } } else if(data.navigation[i].link == link){ page_data = data.navigation[i]; } } if(page_data){ console.log(page_data); } } return page_data; } }]);