Here is an example of a JSON object that I am working with:
{
"conversations":[
{
"_id": "55f1595d72b67ea90d008",
"topic_id": 30,
"topic": "First Conversation",
"admin": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="adcc******">[email protected]</a>",
"__v": 0,
"messages": [
{
"body": "Hello?",
"timestamp": "2015-09-10T10:20:40.000Z",
"from": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2243****">[email protected]</a>",
"_id": "55f1597a72b67ea90d009"
}
],
"to": [
"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1ccc4e1c6cc*********">[email protected]</a>"
]
}
]
}
I am currently designing a custom filter to search for messages within the conversations. The filter's output should include the conversation, message content, sender, and timestamp.
This is how my custom filter is structured:
.filter('searchForMessage', function() {
return function(arr, searchString) {
if (!searchString) {
return arr;
}
var result = [];
searchString = searchString.toLowerCase();
angular.forEach(arr, function(conversation) {
for (var i = 0; i < conversation.messages.length; i++) {
if (conversation.messages[i].body.toLowerCase().indexOf(searchString) !== -1) {
result.push({
conversation: conversation,
message: conversation.messages[i].body,
from: conversation.messages[i].from,
timestamp: conversation.messages[i].timestamp
});
}
}
});
return result;
}
});
The filter successfully retrieves the necessary data but results in an "Error: 10 $digest() iterations reached. Aborting!". Can anyone provide insights into why this error is happening?
Your assistance is greatly appreciated.