我有一個問題,當我想在另一個模塊中創建全局函數打字稿調用靜態函數從其他模塊
utils.ts文件(包含全局函數)
/// <reference path="jquery/index.d.ts" />
/// <reference path="knockout/index.d.ts" />
'use strict';
module com.test.project {
export class utils {
self: any;
constructor() {
this.self = this;
}
public postData(url: string, data: any): any {
var dfd = $.Deferred();
$.ajax({
url: url,
data: JSON.stringify(data),
type: 'post',
contentType: "application/json; charset=utf-8",
dataType: 'json',
cache: false,
success: function(result) {
return dfd.done(result);
},
error: function(result) {
return dfd.reject(result);
}
});
}
}
}
login.ts(稱之爲全球函數內)
/// <reference path="jquery/index.d.ts" />
/// <reference path="knockout/index.d.ts" />
'use strict';
module com.test.project.login {
export class ScreenModel {
self: any;
userName: KnockoutObservable<string>;
password: KnockoutObservable<string>;
constructor() {
this.self = this;
this.userName = ko.observable("") as KnockoutObservable<string>;
this.password = ko.observable("") as KnockoutObservable<string>;
}
private submit(): void {
var dataObject = {
"userName": this.userName(),
"password": this.password()
}
// ↓ error here
com.test.project.utils.postData("loginService.do", dataObject).done(function(result) {
window.location.href = "index.do";
}).reject(function(result) {
alert("error");
});
}
}
$(document).ready(function() {
ko.applyBindings(new ScreenModel());
});
}
模塊com.test.project內部,並在類utils的,通常地,內部像com.test.project模塊的全局函數調用者。[functi全局函數在]和類ScreenModel中。 如何在ScreenModel類中調用全局函數?
我嘗試了兩個,但仍然有錯誤'導入聲明在命名空間不能引用模塊。 login.ts文件 –
刪除所有模塊的東西 – Manu
我試過但仍然錯誤,任何其他的理想? [我目前的代碼](http://i.imgur.com/ATOQdzV.png) –