My dilemma lies in the fact that I have a dynamic table of users extracted from a Firebase database:
<table id="users">
<thead>
...
</thead>
<tbody>
<tr ng-repeat="user in users">
<td data-user-id="{{user.$id}}">{{user.$id}}</td>
</tr>
</tbody>
</table>
function loadUsers($scope, DatabaseFactory) {
DatabaseFactory.users.on('value', function(snapshot) {
var users = snapshot.val();
for(var id in users) {
var user = users[id];
// Locate cell with user ID
var element = angular.element('#users tr td[data-user-id="' + user.id + '"]'); // 1
console.log(element); // 2
}
});
};
In loadUsers()
, my objective is to identify a cell containing a specific user ID. The issue arises when the log statement returns an array with length 0. Why does this discrepancy occur? Interestingly, when I execute statements 1 and 2 in the Chrome console, they yield the desired outcome.