Trying to use a custom filter from an Angular controller is resulting in the error message: 'Cannot invoke an expression whose type lacks a call signature'.
I successfully implemented this on my last project, so I'm confused about what could be wrong now.
Currently, the filter doesn't have any logic as I'm focusing on getting it to compile correctly first.
Here is the code for the filter:
/// <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]);
}
Below is the section where the filter is being called from the controller:
/// <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" />