Skip to content

Instantly share code, notes, and snippets.

@BooneTeam
Created May 10, 2016 22:34
Show Gist options
  • Save BooneTeam/8d6d3bb844521c123a5f1c51de102565 to your computer and use it in GitHub Desktop.
Save BooneTeam/8d6d3bb844521c123a5f1c51de102565 to your computer and use it in GitHub Desktop.
// FACTORY bike-factory.js
angular.module('bike-api', [])
.factory('bikeFactory', ['$http', function ($http) {
var url = 'http://localhost:8080/bike';
var bike = function () {
var self = this;
self.getDefaults().then(function (response) {
self.setUpSuccess(response);
}, function (err) {
self.setUpFail()
});
};
bike.prototype.setUpSuccess = function (response) {
var self = this;
self.brand = response.data.brand;
};
bike.prototype.setUpFail = function () {
var self = this;
self.brand = 'NOT FOUND';
};
bike.prototype.getDefaults = function () {
return $http.get(url);
};
return bike;
}]);
// CONTROLLER bike-invoice.js
angular.module('bike-invoice', ['bike-api'])
.controller('BikeInvoiceController', ['bikeFactory', function(bikeFactory) {
var bike = new bikeFactory();
this.bike = bike;
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment