0

I have text area box in that i will type emails with comma separated then ng List directive split those emails into array now i want to add new line separation also for example when i type emails separated with comma or new line then those emails need to store in arrays.

My code here

<textarea rows="4" cols="50" ng-model="names" ng-list></textarea>

see this link

2 Answers 2

1

Please see demo here

http://plnkr.co/edit/ot3fkEPBBeK7OoeH6LBZ?p=preview

add ng-change to your textbox

 <textarea rows="4" cols="50" ng-model="names" placeholder="Enter your emails" ng-change="split(names)"></textarea>

and in your controller add that

   ....
        $scope.namesList = [];       
        $scope.split = function() {
         var names = $scope.names.replace(/(\r\n|\n|\r)/gm,",").split(',')
         $scope.namesList = names

        }
...
Sign up to request clarification or add additional context in comments.

Comments

0

You could probably do a replace then split something like:

var names = $scope.names.replace('\n', ',').split(',')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.