0

I have an AngularJS service written in JavaScript and i would like to convert this to TypeScript. The Javascript version returns a function immediately. Why would it do this and how would I implement this in TypeScript?

JavaScript

Geisha.service("loginModal", ["$uibModal", "$rootScope", function ($uibModal: angular.ui.bootstrap.IModalService, $rootScope: ICustomRootScopeService) {
function assignCurrentUser(user: User) {
    $rootScope.currentUser = user;
    return user;
}

return function () {
    var instance = $uibModal.open({
        templateUrl: "/Angular/Security/Views/loginTemplate.html",
        controller: "loginModalCtrl"
    });

    return instance.result.then(assignCurrentUser);
}}]);

TypeScript

In TypeScript I have only gone as far as creating the constructor and one of the methods but not sure how to implement the immediate return function

module G.Services {
export class LoginModal {

    $rootScope: ICustomRootScopeService;
    $uibModal: angular.ui.bootstrap.IModalService;

    static $inject = ["$rootScope", "$uibModal"];
    constructor($rootScope: ICustomRootScopeService, $uibModal: angular.ui.bootstrap.IModalService) {
        this.$rootScope = $rootScope;
        this.$uibModal = $uibModal;
    }

    assignCurrentUser(user: User): User {
        this.$rootScope.currentUser = user;
        return user;
    }


}
Geisha.service("loginModal", LoginModal);}

1 Answer 1

1

How to implement the immediate return function

In your case you have a service that is just a function. If you use a class it will be something that has functions. Better if you just use function as you had.

Note

If you are willing to do the refactoring have loginModal.assignCurrentUser(...stuff...) elsewhere instead of loginModal(...stuff...)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.