I want to map a $scope.filters object to a var criteria on the condition if the original fields are null or not.
So lets say I have:
$scope.filters = {
name: 'myName'
lastName: null,
age: null,
}
I want my var criteria to be mapped to non null fields like this:
var criteria = {
name: 'myName';
}
So I have tried like this:
var criteria = {};
angular.forEach($scope.filters, function (value, key, obj) {
if (value != null) {
this.push(obj)
}
}, criteria);
But I guess I'm missing something.
pushing onto? Your$scope.filtersis an Object, not an Array.