Skip to content

Instantly share code, notes, and snippets.

@derwolfe
Created November 7, 2013 19:58
Show Gist options
  • Save derwolfe/7360904 to your computer and use it in GitHub Desktop.
Save derwolfe/7360904 to your computer and use it in GitHub Desktop.
var app = angular.module('App', ['restangular']);
app.config(function (RestangularProvider) {
RestangularProvider.setBaseUrl('/api');
RestangularProvider.setDefaultHeaders({
"headers": { "common": { "Accept": "application/json" } }
});
});
// service that fetches all of the static information that will be needed
app.factory('StaticsService', ['$scope', 'Restangular',
function ($scope, Restangular) {
// here are all of the rest api calls to the application for static pieces of data.
var commoditiesService = Restangular.all('commodities'),
commodityTypesService = Restangular.all('commoditytypes'),
portfoliosService = Restangular.all('portfolios'),
counterpartiesService = Restangular.all('counterparties');
var service = {
getCommodities: function() { return commoditiesService.getList(); },
getCommodityTypes: function() { return commodityTypesService.getList(); },
getPortfolios: function() { return portfoliosService.getList(); },
getCounterparties: function() { return counterpartiesService.getList(); },
};
return service;
}]
);
// controller pulls in the statics, and a specific set of limits
// the data here will be used in a view
app.controller('LimitsListController', ['$scope', 'Restangular',
function ($scope, Restangular) {
$scope.limits = Restangular.all('limits').getList();
}]
);
// XXX Statics service is not being injected, why?
app.controller('StaticsController', ['$scope', 'StaticsService',
function ($scope, Statics) {
$scope.commodities = Statics.getCommodities;
$scope.commodityTypes = Statics.getCommodityTypes;
$scope.portfolios = Statics.getPortfolios;
$scope.counterparties = Statics.getCounterparties;
}]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment