Javascript 如何在现有requiresJS和angular1.2X项目中使用Typescript

Javascript 如何在现有requiresJS和angular1.2X项目中使用Typescript,javascript,angularjs,typescript,requirejs,Javascript,Angularjs,Typescript,Requirejs,如何在现有requiresJS和angular1.2X项目中使用Typescript 我有点不懂打字。我到处寻找答案,但仍然没有找到有效的解决方案 我正在尝试将TS融入现有项目中。我遇到了一些意想不到的问题。该项目使用RequireJS,Angular 1.2X…我已经添加了我需要的所有类型,但现在我不确定如何访问Angular方法,即$q,$http 下面是我在纯JS中通常使用的方法。 define('common/services/ExampleService', [ 'js/app

如何在现有requiresJS和angular1.2X项目中使用Typescript

我有点不懂打字。我到处寻找答案,但仍然没有找到有效的解决方案

我正在尝试将TS融入现有项目中。我遇到了一些意想不到的问题。该项目使用RequireJS,Angular 1.2X…我已经添加了我需要的所有类型,但现在我不确定如何访问Angular方法,即$q,$http

下面是我在纯JS中通常使用的方法。

define('common/services/ExampleService', [
    'js/app'
], function (app) {
    "use strict";

    app.factory('ExampleService', ['$q', '$timeout', '$http', '$log',
        function ($q, $timeout, $http, $log) {

            var someVars = "myApp";

            // service defines the public interface
            var service = {};
            service.example1 = example1;

            return service;

            ////////////////////////////////////////////

            function example1(someOtherVars) {
                $log.log('Example1 has started');

                // all kinds of logic...

                return whatINeed;
            }

        }
    ]);
});
我试图在TypeScript中执行的操作:

///<reference path='../../../app/typings/angular/angular.d.ts'/>
///<reference path='../../../app/typings/requirejs/require.d.ts'/>

define('common/services/ExampleService', [
    'js/app'
], (app) => {
    "use strict";

    app.factory('ExampleService',
        ['$log', '$q', 'RoleService',
            ($log, $q, $http) => {


                class Example1 {
                    private $log: any = $log;

                    constructor($log) {
                        $log.log('Example1 Constructor has started');
                        this.$log = $log;
                    }

                    exampleMethod() {
                        this.$log.log('exampleMethod has been called');

                    }
                }
            }
        ]);
});
///
///
定义('common/services/ExampleService'[
“js/app”
],(应用)=>{
“严格使用”;
应用程序工厂('ExampleService',
[“$log”、“$q”、“RoleService”,
($log,$q,$http)=>{
课堂示例1{
private$log:any=$log;
构造函数($log){
$log.log('Example1构造函数已启动');
这个。$log=$log;
}
示例方法(){
这个.log.log('exampleMethod已被调用');
}
}
}
]);
});