I'm attempting to create a textarea who's input is bound to a JS array where entries correspond to each line in the text area.
I've been attempting to use ngList
with it's optional parameter to specify the delimiter. I can make it work with the default (,
) by adding a comma after each line of the textarea, but I really do not want to require that.
the textarea
<textarea ng-model="list"
rows="5"
ng-list="\n" >
</textarea>
with the input:
test1
test2
test3
The generated output is ["test1\ntest2\ntest3"]
What I am looking for is: ["test1","test2",test3"]
Plnkr Demo
This was updated in Angular 1.3 and now works like this:
<textarea ng-model="list" ng-list=" " ng-trim="false"></textarea>
ng-trim="false"
directive to the <textarea>
tag
From the (1.2) ngList docs:
If specified in form /something/ then the value will be converted into a regular expression.
I just added the /
's and it magically worked!
<textarea ng-model="list"
rows="5"
ng-list="/\n/" >
</textarea>
updated plnkr demo
You could split the output angular gives you:
var result = ["test1\ntest2\ntest3"][0].split("\n")
// result = ["test1", "test2", "test3"]
(Although the solution you've posted is much better!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With