Reputation: 188
Just started writing JavaScript/Angular and can't seem to figure out why this ain't working. I am trying to split a textarea's string into an array on the \n
character inside a controller using $scope.mytext.split("\n")
and I keep getting:
TypeError: undefined is not a function
I have also tried ng-split='\n'
which works fine for text input, but doesn't seem to work for textarea.
Some guidance would be very much appreciated.
Upvotes: 0
Views: 123
Reputation: 108
So going off the little information you gave us, I came up with the following JSFiddle
This takes in a <textarea>
input, binding it to <ng-model>
, and then performing the split function to obtain and array based on where a \n
is. Such that,
$scope.myModel = {
textarea: null,
newTextarea: null
};
$scope.splitTextArea = function(input) {
var newInput = input.split("\n");
$scope.myModel.newTextarea = newInput;
};
Upvotes: 1