On the basis of this post : Angularjs select elements from list and display in textarea
I would like to add functionality :
- Fill textarea on the basis of chosen elements from the list.
- Add additional text inserted by user -> when user decides that he/she wants to add element from the list (some data is written in textarea), select element from the list and "append" to existing text instead of "clear" all textarea and insert values from the list
Could you be so kind and explain me how should I do this ?
Here's a working jsfiddle doing what you ask. Every time you click on a list element it is appended to the textarea.
The main function is a generic directive that you can reuse across controllers:
To use the directive, insert the following in your HTML (at the proper location - see jsfiddle):
data
myModel
is the selection data from the select list, as before.property
mail
is the property to use for extracting values from selected element.model
holds the textarea's content, which you can reuse as you like in your app.Here's the complete relevant HTML code:
Here's the controller and app sections:
Make sure that you define/initialise each directive's model (e.g.
$scope.model = ""
) as above, otherwise it will appear as initially undefined.