Using an array, I am trying to filter and show the unique
information in the list. For that I use the angular
inbuild filter
method.
But I am getting error.
Here is my try (I am filtering by SubProjectName
)
<ul>
<li ng-repeat="project in projectNames | unique: 'SubProjectName' ">
{project.SubProjectName}}
</li>
</ul>
Live Demo
I think you are looking for an answer like this
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.projectNames=projects
$scope.Id = "1";
$scope.SubProjectName="Retail Building";
})
.filter('unique', function() {
return function(projects, subProjectName) {
var newprojects =[];
projects.forEach(function(project){
if(project.SubProjectName === subProjectName)
newprojects.push(project);
});
return newprojects;
};
});
<li ng-repeat="project in projectNames | unique:SubProjectName">{{project.SubProjectName}}</li>
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With