我試圖從角度控制器調用自定義過濾器,但出現錯誤: '無法調用鍵入缺少呼叫簽名'。嘗試在'錯誤TS2349:無法調用其類型缺少呼叫簽名的表達式'中調用自定義過濾器結果
我在最後一個項目中對此進行了這樣的實施,所以我對於什麼是錯誤感到不知所措。
該過濾器在此處不包含任何邏輯,因爲我需要先編譯它。
這裏是過濾器:
/// <reference path="../../typings/reference.ts" />
module app {
'use strict';
/**
* Filter models
*/
export class ModelFilter {
public static Factory() {
return function(input: string) {
console.log(input);
return input;
}
}
}
angular.module('app')
.filter('modelFilter', [ModelFilter.Factory]);
}
而且控制器,其中其稱爲:
/// <reference path="../../typings/reference.ts" />
module app {
'use strict';
interface ISearchController {
vehicles: IVehicles;
models: any;
setVehicles(): void;
updateModels(make: string): void;
}
class SearchController implements ISearchController {
static $inject = [
'VehicleMakeService',
'VehicleModelService',
'$filter'
];
constructor(private vehicleMakeService: VehicleMakeService,
private vehicleModelService: VehicleModelService,
private $filter: ng.IFilterService,
public vehicles: IVehicles,
public models: any) {
this.setVehicles();
}
setVehicles(): void {
this.vehicleMakeService.getVehicles().then((data) => {
this.vehicles = data;
});
}
updateModels(make: string): void {
var test = this.$filter('modelFilter')(make); // Error here
}
}
angular.module('app').controller('SearchController', SearchController);
}
reference.ts:
/// <reference path="./tsd.d.ts" />
//grunt-start
/// <reference path="../app/app.config.ts" />
/// <reference path="../app/app.module.ts" />
/// <reference path="../app/app.route.ts" />
/// <reference path="../app/home/home.controller.ts" />
/// <reference path="../app/home/home.route.ts" />
/// <reference path="../app/models/vehicles.model.ts" />
/// <reference path="../app/results/results.controller.ts" />
/// <reference path="../app/results/results.route.ts" />
/// <reference path="../app/services/cars.service.ts" />
/// <reference path="../app/services/vehicles.make.service.ts" />
/// <reference path="../app/services/vehicles.models.service.ts" />
/// <reference path="../app/templates/search.controller.ts" />
/// <reference path="../app/templates/search.filter.ts" />
//grunt-end
tsd.d.ts:
/// <reference path="angularjs/angular.d.ts" />
/// <reference path="jquery/jquery.d.ts" />
/// <reference path="angular-ui-router/angular-ui-router.d.ts" />
/// <reference path="angularjs/angular-resource.d.ts" />
我試過你的解決方案,但我得到完全相同的錯誤。僅供參考,使用grunt-ts創建reference .ts,其中包含對tsd.d.ts的引用,其中包含對angular.d.ts的引用,所以基本上reference.ts包含對應用程序中所有ts文件的引用以及絕對鍵入的文件。我已更新我的問題以顯示此內容。 – AngularBoy
你可以將修改過的代碼發佈到pastebin嗎? –
我使用TypeScript 1.6.2。無論如何,你可以從這裏https://pastee.org/5hfp代碼http://www.typescriptlang.org/Playground看到它的作品。 –