如何在现有的requiresJS和angular1.2X项目中使用Typescript
我有点像TypeScript的菜鸟。我到处寻找答案,但仍未找到有效的解决方案。
我正在尝试将TS混合到现有项目中。我遇到了一些无法预料的问题。该项目使用RequireJS,Angular 1.2X ...我已经添加了我需要的所有输入但现在我不知道如何访问角度方法,即$ 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');
}
}
}
]);
});