Z
Z
zlodiak2018-05-09 21:27:29
Angular
zlodiak, 2018-05-09 21:27:29

How to make search for dynamic elements in DOM?

There is a component that displays In the markup of the parent component, as a result of user actions, several instances of this component appear and are removed. In the parent component, I implemented the search for this textarea through a native querySelector. But I would like to use the tools of angular. Please tell me what to use and generally in which direction to dig? The problem is that if you mark the element with #name and then try to get it in the parent element through @ViewChild, then the element is not found because, as I said above, elements appear and disappear dynamically
<textarea></textarea>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-05-10
@zlodiak

The problem is that if you mark the element with #name and then try to get it in the parent element through @ViewChild, then the element is not found because, as I said above, elements appear and disappear dynamically
You can do the following: through ViewChild, get the element in the child component, and in the parent - instances of child components through ViewChildren, from which you can get what you need. It might look like this .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question