Created
November 2, 2015 17:34
-
-
Save techverx/e5c0f8e89788b8a7796d to your computer and use it in GitHub Desktop.
An Angular (1.0) service written in TypeScript
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
/// <reference path="../../typings/angularjs/angular.d.ts" /> | |
/// <reference path="../../typings/angularjs/angular-route.d.ts" /> | |
module TMA { | |
interface ILoginService { | |
authenticate(username: string, password: string) : ng.IPromise<ng.IHttpPromiseCallbackArg<User>>; | |
} | |
export class LoginService implements ILoginService { | |
static $inject = ["$http", "$q"]; | |
constructor(private $http: ng.IHttpService, private $q: ng.IQService) { | |
} | |
authenticate(username: string, password: string) : ng.IPromise<ng.IHttpPromiseCallbackArg<User>> { | |
var defer = this.$q.defer(); | |
this.$http({ | |
method: "POST", | |
url: "http://www.trackmyassets.biz/api/users/authenticate/", | |
data: { | |
email: username, | |
password: password | |
} | |
}).success((data: any, status: number, header: ng.IHttpHeadersGetter, config: ng.IRequestConfig) => { | |
var u = new User(data.user); | |
defer.resolve(u); | |
}) | |
return defer.promise; | |
} | |
} | |
angular | |
.module("TMA") | |
.service("LoginService", LoginService); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment