I thought this was going to be the easy part but been going trough google / stack overflow for the past 3 hours with no luck.
I have a straight foward ng-repeat where I want to list everything in my data2 where the ref_id column matches the unique ID of my data1.
data1: [ {id: 1, name: "Bob"}, {id: 2, name: "Diane"}, {id: 3, name: "Ross"}, {id: 4, name: "Jimbo"}, ];
data2: [ {ref_id: 1, Result: "Fries"}, {ref_id: 1, Result: "Burger"}, {ref_id: 7, Result: "Burger"}, {ref_id: 8, Result: "Nothing"}, ];
So this is what I came up with:
<div ng-repeat="result in data2 | filter: { ref_id: data1.id }" > {{ result.Result }} </div>
It seems to be ignoring my filter and just spitting out everything. So i thought maybe it dosent like the array in my filter so I created a custom filter:
<div ng-repeat="result in data2 | filter: Test()" > {{ result.Result }} </div>
$scope.Test = function(item){
return angular.forEach($scope.data1, function(value, key) {
return value.id === item.ref_id;
}
}
But this simply does not work either, its giving me undefined variables but I think it dosent like the way I use the function. I just want my ng-repeat to display items that have a matching ID to go with my ref_ID column.
Any ideas?