function(){ // Runs during compile return { // name: '', // priority: 1, // terminal: true, // scope: {}, // {} = isolate, true = child, false/undefined = no change controller: function($scope, $element, $attrs, $transclude, $http) { var self = this; /** * Initialise Controller */ self.Initialise = function() { self.log("Initialising Scope."); $scope.machineObj = []; if ($scope.user !== undefined) { self.log("User exists"); if(typeof $scope.user.software_key.constructor == 'Array') { self.log("Key is an array"); angular.forEach($scope.user.software_key, function(software_key, key){ var url = 'URL' + software_key + '/DATA'; self.log(url); $http.get(url). success(function(data/*, status, headers, config*/) { if(data.id === 'error') { self.log(data); } else { self.log("Processing data."); $scope.machineList = data; angular.forEach($scope.machineList,function(machine,index){ $scope.machineObj.push({ Name: machine.Name, Address: machine.Address, Key: machine.Key }); }); } }). error(function(data/*, status, headers, config*/) { alert(data); }); }); } } else { self.log("User does not exist"); var url = 'URL' + $scope.user.key + '/DATA'; self.log(url); $http.get(url). success(function(data/*, status, headers, config*/) { if(data.id === 'error') { console.log(data); } else { self.log("Processing data."); angular.forEach($scope.machineList,function(machine,index){ $scope.machineObj.push({ Name: machine.Name, Address: machine.Address, Key: machine.SoftwareKey }); }); console.log($scope.machineObj); } }). error(function(data/*, status, headers, config*/) { alert(data); }); } } /** * Handle Click event on Machine list item * @param {string} $keyword */ self.alertMe = function($keyword){ alert($keyword); }; /** * Write to the Console * @param {string} message */ self.log = function(message) { console.log(message); }; // Initialise Directive self.Initialise(); }, restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment template: '
  • {{::machine.Name}}
  • ',
    replace: true, }; } ); .directive('machineList', function(){ // Runs during compile return { // name: '', // priority: 1, // terminal: true, // scope: {}, // {} = isolate, true = child, false/undefined = no change controller: function($scope, $element, $attrs, $transclude, $http) { $scope.machineObj = []; $scope.alertMe = function($keyword){ alert($keyword.Address); }; if($scope.user !== undefined) { if($scope.user.software_key.constructor === Array) { angular.forEach($scope.user.software_key, function(software_key, key){ $http.get('http://54.213.13.56/api/' + software_key + '/remotes'). success(function(data/*, status, headers, config*/) { if(data.id === 'error') { console.log(data); } else { //console.log(data); $scope.machineList = data; angular.forEach($scope.machineList,function(machine,index){ $scope.machineObj.push({ Name: machine.Name, Address: machine.Address, SoftwareKey: machine.SoftwareKey }); }); //alert($scope.machineObj.length); console.log($scope.machineObj); //$rootScope.user = data; /*console.log($scope.user.software_key);*/ //alert($scope.user.software_key.constructor === Array); //alert(data); //$rootScope.loggedInUser = $scope.user.email; //$location.path("/"); } }). error(function(data/*, status, headers, config*/) { alert(data); }); }); } } else { $http.get('http://54.213.13.56/api/' + $scope.user.software_key + '/remotes'). success(function(data/*, status, headers, config*/) { if(data.id === 'error') { console.log(data); } else { //console.log(data); angular.forEach($scope.machineList,function(machine,index){ $scope.machineObj.push({ Name: machine.Name, Address: machine.Address, SoftwareKey: machine.SoftwareKey }); }); //alert($scope.machineObj.length); console.log($scope.machineObj); //$rootScope.user = data; /*console.log($scope.user.software_key);*/ //alert($scope.user.software_key.constructor === Array); //alert(data); //$rootScope.loggedInUser = $scope.user.email; //$location.path("/"); } }). error(function(data/*, status, headers, config*/) { alert(data); }); } }, // require: 'ngModel', // Array = multiple requires, ? = optional, ^ = check parent elements restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment template: '
  • {{::machine.Name}}
  • ',
    // templateUrl: '', replace: true, // transclude: true, // compile: function(tElement, tAttrs, function transclude(function(scope, cloneLinkingFn){ return function linking(scope, elm, attrs){}})), //link: function(scope, iElm, iAttrs, controller, $http) {} }; });