I have several filters working perfectly on ng-repeat. However, the code seems unnecessarily long for the actual action of the filters on the set, and I wonder if there is a better way.
Here is an example filter - this bit is fine with me (if anyone has no advice) - they all follow a similar structure:
app.js
.filter('taskClient', function() { return function (items, clientId) { if (!clientId) { return items; } var filtered = []; angular.forEach(items, function(item) { if (item.client) { if (item.client.id === clientId) { filtered.push(item); } } }); return filtered; } })
And, as I said, there are several. Then, on my ng-repeat, I implement them as such ( , this is a bit that seems complicated to maintain and is too long, and would be appreciated by information on any best practices ):
Tasks-index.html
<md-list-item icp-task-line ng-repeat="task in TasksCtrl.tasks | taskOwner: TasksCtrl.selectedUserFilter | taskClient: TasksCtrl.clientId | taskDepartment: TasksCtrl.departmentId | taskPriority: TasksCtrl.priority | taskWithClient: TasksCtrl.withClient | taskEndDate: TasksCtrl.endDate | filter: {progress: 0} | filter: searchText | orderBy: TasksCtrl.orderTasks" class="md-2-line"></md-list-item>
Judging by how many scrolls are here, I think you can see my problem with the above code. In order to view the duration of tasks (also divided into completed, in progress, etc.), I must select all the filters again.
Is there a better way to implement these filters?
I am also concerned that after reading this article I donβt understand the difference between state filters and non-statistical ones - are these filters optimized for performance above?
source share