将函数从Javascript返回到TypeScript

时间:2015-12-10 11:16:59

标签: javascript typescript

我刚刚开始使用Typescript,并希望将以下Javascript转换为Typescript。

第一个代码块是实际的JS,第二个是我到目前为止的TypeScript。

我认为这是最正确的,但我遇到的麻烦是Javascript结束时的返回功能。我如何在我的TypeScript代码中写这个位?

var ABC = ABC || {};

ABC.navigationService = function () {

var navigate = {};

function navigateChart(e, query) {
}

function drillChart(direction, type, query) {
}

function canDrillUp(series, query) {        
}

function drillUp(series, query) {
}

return {
    navigate: navigateChart,
    drill: drillChart,
    canDrillUp: canDrillUp,
    drillUp: drillUp
}
}

angular.module("MyApp").service("navigationService", [ABC.navigationService]);

并且使用typescript,这是我到目前为止所拥有的,包括我想要在Javascript中返回结果的函数: -

module ABC.Visualisation.Services {
'use strict';
var xPos = 0;
var yPos = 0;
var canDrilldownPoint = false;
var canDrillupPoint = false;
var canDrilldownSeries = false;
var canDrillupSeries = false;

var navigate = {
    loading: false,
    showGui: false,
    canDrilldownPoint: canDrilldownPoint,
    canDrillupPoint: canDrillupPoint,
    canDrilldownSeries: canDrilldownSeries,
    canDrillupSeries: canDrillupSeries,
    x: xPos,
    y: yPos
};

export class NavigationService implements INavigationService {

    public navigateChart(e: any, query: any) {

    }

    public drillChart(direction: string, type: string, query: any): void {
    }


    public canDrillUp(series: any, query: any): boolean {
    }

    public drillUp(series: any, query: any): void {
    }


}
}

angular.module("MyApp").service("NavigationService", [ABC.Visualisation.Services.NavigationService]);

1 个答案:

答案 0 :(得分:0)

1)我相信

angular.module("MyApp").service("NavigationService", [ABC.Visualisation.Services.NavigationService]);

应该是

angular.module("MyApp").service("NavigationService", ABC.Visualisation.Services.NavigationService);

2)这是将变量放入模块的方法:Creating a variable with get/set inside a module in Typescript