Hi

I have a angular service 'MyService' like the one below

angular.module('myApp.services', [], function($provide) {
$provide.factory('MyService', ['$http', function(http) {
function MyService() {

}

MyService.prototype = {
getContents: function(id) {
var contents;
http.get('/myapp/getcontents?id=' + id).success(function(data) {
contents = data;
});

return contents;
}
};

return (MyService);
}]);
});

I want the getContents method of MyService to call my ajax web service like its doing, then in some way share data with the rest of the function so that I can return contents to my controller, which I've already injected MyService into.

The way I'm doing it is wrong, as var contents is not visible inside the http.get().success(function data(){ callback.

What is the proper way to do this?

Thanks, Aussieguy