Created
December 3, 2014 21:15
-
-
Save michaeldjeffrey/bbd37af3b3bd3592c351 to your computer and use it in GitHub Desktop.
Slim controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('ARM').factory('FeederFactory', function($http){ | |
var data = { | |
loantypes: [], | |
locations: [], | |
regions: [], | |
reports: [] | |
}; | |
function getLoanTypes(){ | |
$http.get('/loantypes').then(function(response){ | |
data.loantypes = response.data.data | |
}); | |
} | |
function getLocations(){ /* same pattern as getLoanTypes() */ } | |
function getRegions(){ /* same pattern as getLoanTypes() */ } | |
function getReports(){ /* same pattern as getLoanTypes() */ } | |
function getObject(){ | |
return data; | |
} | |
function init(){ | |
// trigger http calls to get data. | |
getLoanTypes(); | |
getLocations(); | |
getRegions(); | |
getReports(); | |
} | |
return { | |
init: init | |
getObject: getObject, | |
getRegions: getRegions, | |
getReports: getReports, | |
getLoanTypes: getLoanTypes, | |
getLocations: getLocations, | |
} | |
}) | |
angular.module('ARM') .controller('MainController', function( | |
$scope, | |
$state, | |
GlobalsFactory, | |
UsersFactory, | |
FeederFactory, | |
LoansFactory | |
) { | |
// feeder things can now be referenced as $scope.feeder.loantypes. | |
// any updates to anything in feeder will be reflected anywhere that's using it. | |
FeederFactory.init(); | |
$scope.feeder = FeederFactory.getObject(); | |
$scope.getColor = function(val){ | |
var colors = ['gray', 'green', 'yellow', 'red', 'blue', 'green_off', 'yellow_off']; | |
return colors[val] || 'gray'; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment