UPDATE: I have figured it out and solved this question. To do what I was hoping to accomplish here. Do the following:
var app = angular.module('myApp', []);
app.factory('server', ['$http', function($http) {
return {
getResults: function(blah) {
var req = {};
req.blah = blah;
return $http({
method: 'GET',
url: 'blah',
params: req
});
}
}
}]);
app.controller('myCtrl', ['$scope', 'server', function($scope, server) {
$scope.getResults = function() {
server.getResults($scope.blah)
.success(function(data) {
$scope.results = data;
}).error(function(data) {
$scope.results = {
"Blah": "something"
};
});
};
}]);
Original post: My goal is to get the UI to do a GET request to a RESTful server, and obtain a JSON in return. So in my myApp.js, I have:
var app = angular.module('myApp', []);
app.factory('server', ['$http', function($http){
var server = {};
server.getResults = function(blah) {
return $http({
method: 'JSONP',
url: 'blah'
});
}
return server;
}]);
app.controller('MainCtrl', ['$scope', function($scope, server){
$scope.results = server.results;
}]);
I should clarify that the response I should get from the server is a JSON object that looks like this:
var blah = {"Blah": "something"}
frontend_server.resultsproperty but instead, agetResults()function that returns a promise.