Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The dynamically generated DOM ID, created using Angular's NgFor, is not able to be searched through JS because it is generated at runtime and may not exist in the HTML when the JS code is executed. This is because Angular creates the DOM elements dynamically based on the data that is bound to the NgFor directive. As a result, the dynamically generated DOM IDs are not predictable and cannot be anticipated by the JS code.

To overcome this, you can use Template Reference Variables in Angular to reference an individual element in the NgFor loop. This allows you to interact with the element directly, without having to search for it through its ID. Another alternative would be to use Angular's built-in event binding to handle interactions with the dynamically generated elements, rather than searching for them by their ID in the DOM.