У меня есть фильтр, который я хотел бы использовать с нг-повторомAngularJS фильтр не работает должным образом
Там нет консольных сообщений появляется в браузере, так что я не в состоянии видеть, что происходит на.
Не могли бы вы поставить меня в правильном направлении, где я ошибаюсь в коде ниже? Заранее спасибо!
Моделиmodule Models {
"use strict";
export interface IMember {
Id: number;
// ...
}
export interface IForumContent extends IMember {
RowId: string;
// ...
}
}
Контроллеры
module Controllers {
"use strict";
export class ForumController extends ControllerBase.Controller {
log: ng.ILogService;
scope: IForumControllerScope;
static $inject = ["$scope", "$log"];
constructor($scope: IForumControllerScope, $log: ng.ILogService) {
super($scope);
this.log = $log;
// ...
}
// ...
}
}
Фильтры
module Filters {
"use strict";
export var $inject = ["$log", "$filter"];
export function UniqueFilter($log: ng.ILogService, $filter: ng.IFilterService) {
$log.log("Test 1");
console.log("Test 1");
return function(items: Array<Models.ForumContent>, filterOn: string) {
$log.log("Test 2");
console.log("Test 2");
if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) {
var newItems = [];
var extractValueToCompare = function(item) {
if (angular.isObject(item) && (angular.isString(filterOn))) {
return item[filterOn];
} else {
return item;
}
};
angular.forEach(items, function(item) {
var valueToCheck, isDuplicate = false;
for (var i = 0; i < newItems.length; i++) {
if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) {
isDuplicate = true;
break;
}
}
if (!isDuplicate) {
newItems.push(item);
}
});
items = newItems;
}
return items;
}
}
}
Глобальные
var applicationModule = angular.module("app", []);
applicationModule.filter('uniqueFilter', Filters.UniqueFilter);
applicationModule.controller("forumController", Controllers.ForumController);
Html
<table class="table table-hover">
<tbody>
<tr>
<th>Content</th>
</tr>
<tr ng-model="forumContent" ng-repeat="forumContent in forumRepository.Forum.Contents | filter: uniqueFilter:'Id'">
</tr>
</tbody>
</table>
проверка если * forumRepository.Forum.Contents * пуст – Vivek
это не так, если я свяжу его с кнопкой, чтобы отключить фильтр, или если я удалю тег фильтра, я могу увидеть все записи – cilerler