Я использую контроллер внутри своей директивы. Я объявила функцию (change (searchAttribute: string)) в конструкторе контроллера, которая будет внутренне использовать фильтр, но я получаю исключение во время выполнения. «Этот фильтр не является функцией».
У меня есть много примеров на google, которые вводят $ filter сервис таким же образом, но я не могу понять, почему он не работает для меня.
Мой код:
module app.directive {
interface MyDirectiveScope extends ng.IScope {
myModel: any[];
change(searchAttribute: string);
}
class MyController {
static $inject = ['$scope', '$filter'];
constructor(public $scope: MyDirectiveScope, public $filter: ng.IFilterService) {
//code
$scope.change = function (searchAttribute) {
$scope.myModel = this.$filter('filter')($scope.myModel, searchAttribute); //error : this.$filter turns out to be undefined here
};
}
}
class MyDirective implements ng.IDirective {
static instance(): ng.IDirective {
return new MyDirective;
}
restrict = "E";
replace = true;
templateUrl = "myTemplate.html";
controller = MyController;
scope = {};
}
angular.module("myModule")
.directive("myDirective", MyDirective.instance);}