Well I knocked up a jsFiddle version myself:
CodePerfect: Filter Issues[
^]
So there are plenty of issues here, but let's highlight some basic ones
1: Loop counter reset
Your filter for loops:
for (var i = 0; i < $scope.Products.length; i++) {
var j = 0;
if ( $scope.Products[i].Qty >= compValue) {
newArray[j] = $scope.Products[i];
j = j + 1
}
}
2: add to an array
so at the start of each loop it sets j = 0? do you want j to reset every loop?
newArray[j]
why? Just do this:
let result = []
for(...){
result.push(item)
}
No need to iterate through the result array. just add new items with a push.
3: welcome to Ecmascript6 (or javascript as you now it)
Check this out:
newArray = $scope.Products.filter(p=>p.Qty>=compValue)
did you just see that? wow :P
So here is your whole filter function so far (with switch)
$scope.onChange = function(compFilter, compValue) {
$scope.Products = $scope.allProducts
let newArray = [];
switch(compFilter)
{
case '=':
newArray = $scope.Products.filter(p=>p.Qty==compValue)
break;
case '>=':
newArray = $scope.Products.filter(p=>p.Qty>=compValue)
break;
default:
newArray = $scope.Products.filter(p=>p.Qty<=compValue)
break;
}
$scope.Products = newArray;
}
I made a few small changes, but you get the idea.
We can go much further. You are using about 5% of angular's potential and about 0.1% of javascript. I will expand if you like. We can make this simple device very neat indeed