Currently, I have a filter object that looks like this:
{
name: 'text',
value: 'xxx',
field: 'firstname'
}
This object represents a filter for a specific field and is updated whenever input field values change. I am attempting to store this object in an array using the following method:
$scope.active_filters[filter.field] = filter;
This way, I can easily identify which filter belongs to which field. The filtering process needs to take place on the server side, so I want to send this array to my API.
$http.post(url, $scope.active_filters)
Upon inspecting in Chrome, I see that there is an array with the desired element, but its length is shown as 0:
[status: Object]
length: 0
status: Object
field: "status"
name: "text"
value: "x"
__proto__: Object
__proto__: Array[0]
However, when I attempt to send the data, the object is NOT included in the request. If I manually add the object using
$scope.active_filters.push(filter)
, it does get sent to the server, but it has the index of 0 instead of the desired value.
How can I accomplish both goals - having a named index in my array and successfully sending the data to the API?