Created
May 10, 2016 22:34
-
-
Save BooneTeam/8d6d3bb844521c123a5f1c51de102565 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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