K
K
Keshabit2015-10-23 11:59:05
JavaScript
Keshabit, 2015-10-23 11:59:05

How to get list of users from dynamically added select elements?

1. I created a directive that, when a button is clicked, adds a drop-down list of users to the page. And so you can add many lists of users each time you click on the button.
2. Now, after I have selected in all lists of users, I have to get them into the controller.
How can I get a list of users from dynamically created selects?
Here is the code on the plunker that explains the problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-10-23
@Keshabit

jquery-style again...
1) never work directly with the DOM. Never ever. If you can do without it, then do without it. Use ng-repeat instead of your ugly append and $parse tricks. Instead of ng-repeat for options, use ng-options.
2) instead of link try to use directive controller. Let the data drive the view, not the view data. link is used for only one purpose - work with $scope and c DOM. Avoid this place.
3) In order to notify that something has changed - use callbacks. Read about the isolated scope and the magic symbol &.

I
imelos, 2015-10-23
@imelos

plnkr.co/edit/XcR9CR2ldnWdhNcgE1DK?p=preview
Something like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question