Array.indexOf()
and the ===
operator compare object references and are only true when comparing references to the same instance of an object. {quote: q, controller: c}
is an entirely different object instance than those in the array, even if its properties match an object in the array exactly.
Angular has a helper function called angular.equals()
that checks of 2 objects are equivalent. You can use it in place of the ===
...
$scope.containsObject = function(obj, list) {
var i;
for (i = 0; i < list.length; i++) {
if (angular.equals(list[i], obj)) {
return true;
}
}
return false;
};