I am working on an onclick function that involves data stored in objects.
$scope.messages = [
{"id": "1"},
{"id": "2"},
{"id": "3"},
{"id": "4"},
];
$scope.selection = {
ids: {}
};
$scope.sendMe = function(message) {
//send the data with `id` and `check state`
}
function onMessageArrived(response) {
_.each($scope.message, function (n, key) {
if (responseID == n.id) {
var boolValue = response.payloadString == 'true';
$scope.selection.ids[n.id] = boolValue;
}
});
}
Currently, I am using ng-repeat to loop and create checkboxes dynamically.
<div ng-repeat="message in messages" ng-class="message.type">
<input type="checkbox" class="switch-input" ng-click="sendMe()" ng-model="selection.ids[message.id]">
</div>
Everything works fine, but when a message arrives in my onMessageArrived
function, it updates $scope.selection.ids[n.id]
to either true
or false
, like this:
$scope.selection = {
ids: {"1": true}
}
However, the issue is that the checkbox does not update in real-time. What could be the reason for this?
Any help would be appreciated. Thank you.