I have an input of ng-tags-input with autocomplete. The autocomplete can show "users", "organisations" and "Mailing lists" (which contains an array of users and another array of organisations).
When I click on a user in the autocompletion, a user tag is created. When I click on an organisation in the autocompletion, an organisation tag is created. But when I click on a Mailing List in the autocompletion, I would like to add every users and every organisations contained in the mailing list as individual tags. I've searched many ways to do this but I can't figure out how to do this last point...
ng-tags-input propose the function $removeTag to remove a tag but I haven't found any function to add a tag with Javascript. I would be very grateful if anybody would have any clue! Thanks!
You want to add tags into ng-tags-input. Which translates to - I want to mutate the model bound to ng-tags-input. Or, I want to push elements inside the array of objects which contains the tags. So you basically want to push objects into the model bound to your ng-tags-input directive.
<tags-input ng-model="tagsModel" >
You need to attach handler to the event when a suggestion is selected from the list. I guess the autocomplete feature itself allows you to bind a scope function to it. Then, If it is the type 'Mailing List', then iterate through each element of selected array, contruct the tags (basically an object of form { text: 'value'} ) and push it into your tagsModel.
Hope it helps. If you attach a plnkr, I would be able to better answer this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.