I
I
Isherath2018-09-12 19:17:35
Angular
Isherath, 2018-09-12 19:17:35

How to make one directive for multiple similar DOM elements?

I need to make custom select. To be more precise, instead of tags, make a directive that will replace the regular select.
There is a directive that does this. Namely, when hovering over a block (fake input), a ul appears with a list. Clicking on a list item adds this item to the array, clicking again removes the value with the key from the array. Then, all the data collected in the array is sent to the server ... but there are no more directives to work with. She only collects data.
There can be many such "selects" on one page. Therefore, it is necessary to somehow distinguish between all this. Let's say there is a list with countries and a list with categories of something. Accordingly, it is necessary to divide the scope so that the data from the lists does not fall into the same array. And also, on each click, the directive inserts a span with the list value into a fake input (normal div).
More shortly, an essence that it is necessary to delimit scopes somehow. How to do this is still unclear. Writing a directive for each element, while copy-pasting the same code is stupid. Tell me please.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question