我已经设法从 Web API 返回可以使用 Angular 显示的数据。但现在我需要能够过滤这些数据。我创建了一个指令来传递我想要过滤的参数,但我找不到任何关于我将使用什么语法进行过滤的信息。这是我的服务:
var fixtureService = angular.module("fixtureService", ["ngResource"]).factory("Fixture", function ($resource, $rootScope) {
fixtureService.addFilter = function (seasonNo) {
alert(seasonNo);
//do the filtering here?
};
return $resource(
"/api/fixture/:Id",
{ Id: "@Id" },
{ "update": { method: "PUT" } }
);
});
任何帮助将非常感激!
编辑:这是我的指令:
app.directive("season", function () {
return {
restrict: 'E',
controller: SeasonCtrl,
template: '<select name="Seasons" ng-model="selectedSeason" ng-options="season.SeasonNo for season in seasons" ng-change="handleChange(season)">\
<option value=""> --Valitse-- </option>\
</select>',
link: function (scope, elem, attrs, ctrl) {
scope.handleChange = function () {
if (scope.selectedSeason != null) {
fixtureService.addFilter(scope.selectedSeason.SeasonNo);
} else {
fixtureService.clearFilter();
}
};
}
};
});