Skip to content

Instantly share code, notes, and snippets.

@IEvangelist
Created September 2, 2016 01:09
Show Gist options
  • Save IEvangelist/956a05cdfdeeccf975414ca47f4c198c to your computer and use it in GitHub Desktop.
Save IEvangelist/956a05cdfdeeccf975414ca47f4c198c to your computer and use it in GitHub Desktop.
module ExampleModule {
export class ExampleService implements IExampleService {
static $inject = ["$http", "$q"];
private $http: ng.IHttpService;
private $q: ng.IQService;
constructor($http: ng.IHttpService,
$q: ng.IQService) {
this.$http = $http;
this.$q = $q;
}
public getFooBars(): ng.IPromise<FooBar[]> {
var deferred = this.$q.defer<FooBar[]>();
this.$http
.get("api/foobar")
.success((data) => {
deferred.resolve(data);
})
.error((error) => {
console.log("An error occurred when requesting api/foobar.", error);
deferred.reject(error);
});
return deferred.promise;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment