使用TypeScript的AngularJS应用程序无法调用未定义的方法

使用TypeScript的AngularJS应用程序无法调用未定义的方法,angularjs,typescript,Angularjs,Typescript,一般来说,我对AngularJS和web开发还不熟悉,所以这可能是一个愚蠢的问题,但我无法理解 我有我的主应用程序 /// <reference path="../../references.ts" /> angular.module("mainApp", []) .config(($routeProvider: ng.IRouteProvider) => { $routeProvider .when("/", {

一般来说,我对AngularJS和web开发还不熟悉,所以这可能是一个愚蠢的问题,但我无法理解

我有我的主应用程序

/// <reference path="../../references.ts" />


angular.module("mainApp", [])
    .config(($routeProvider: ng.IRouteProvider) => {
        $routeProvider
            .when("/", {
                templateUrl: "/app/module/mainApp/partials/main.html",
                controller: AppController,
                //datacontext
                controllerAs: "dc"
            })
            .when("/login", {
                templateUrl: "/app/module/mainApp/partials/login.html",
                controller: LoginController,
                controllerAs: "dc",

            })
    })

    .run(($rootScope: ng.IRootScopeService, $location: ng.ILocationService, AuthService) => {
        $rootScope.$on("$routeChangeStart", (event, next, current) => {
            if (!AuthService.IsLoggedIn()) {
                if (next.templateUrl == "app/module/mainApp/partials/login") {
                    return;
                } else {
                    $location.path("/login");
                }
            }
        });
    })
我所有的.ts文件都在references.ts中,我已经将.js文件添加到index.html中

当我运行此命令时,我得到一个错误,无法调用未定义的方法“GetToken()”


AngularJS是否应该在AuthService中注入我的TokenHandler?

这些行几乎肯定是错误的;你打算在这里传递原型做什么

angular.module("mainApp").factory("TokenHandler", () => TokenHandler.prototype);

angular.module("mainApp").factory("AuthService", () => AuthService.prototype);
我想你想要:

angular.module("mainApp").factory("TokenHandler", () => new TokenHandler());

angular.module("mainApp").factory("AuthService", () => new AuthService());

这些台词似乎几乎肯定是错的;你打算在这里传递原型做什么

angular.module("mainApp").factory("TokenHandler", () => TokenHandler.prototype);

angular.module("mainApp").factory("AuthService", () => AuthService.prototype);
我想你想要:

angular.module("mainApp").factory("TokenHandler", () => new TokenHandler());

angular.module("mainApp").factory("AuthService", () => new AuthService());