After spending the last 3 hours searching on Google and Stack Overflow, I thought this would be easy, but I'm still stuck.
I have a simple ng-repeat where I need to display everything from data2 that matches the unique ID in my data1's ref_id column.
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"}, ];
This is what I tried:
<div ng-repeat="result in data2 | filter: { ref_id: data1.id }" > {{ result.Result }} </div>
The filter seems to be not working as expected. So, I attempted to create 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;
}
}
However, this approach also failed as it resulted in undefined variables. I suspect it has something to do with how I implemented the function. All I want is for ng-repeat to show items with matching IDs for the ref_ID column.
Any suggestions?