Skip to content Skip to sidebar Skip to footer

Filter An Array Of Objects By A Property Containing A Substring In Angularjs

Let's say i have an array like: array = [{ title: 'foo1', content: 'bar1' },{ title: 'foo2', content: 'bar2' },{ title: 'foo3', content: 'bar3' }]; Now i

Solution 1:

The filter filter (yeah, I know) does a contains filtering...

I pasted your code (working) into PLNKR and filtered on 3 and got back the title: 'foo3' element

array = [{
  title: "foo1",
  content: "bar1"
},{
  title: "foo2",
  content: "bar2"
},{
  title: "foo3",
  content: "bar3"
}];

$scope.filteredData = $filter('filter')(array, {
  title: "3",
});

Solution 2:

You would need to write your own filter. Check this answer on how to achieve what you want.

Post a Comment for "Filter An Array Of Objects By A Property Containing A Substring In Angularjs"