AngularJS format array values in textarea -


i have angularjs application, in have array.

  $scope.data[0] =  x1;   $scope.data[1] =  x2; 

and text area

  <textarea ng-model="data"> </textarea> 

i can see textarea contains values x1, x2 (separated comma). want show values on separate lines. meaning array values should separated new line character not comma. need write filter this?

you can write directive modifies how ng-model converts variables input values , back. i'm writing off top of head, have no idea if it's right, might it:

app.directive('splitarray', function() {     return {         restrict: 'a',         require: 'ngmodel',         link: function(scope, element, attr, ngmodel) {              function fromuser(text) {                 return text.split("\n");             }              function touser(array) {                                         return array.join("\n");             }              ngmodel.$parsers.push(fromuser);             ngmodel.$formatters.push(touser);         }     }; }); 

and can use this:

  <textarea ng-model="data" split-array> </textarea> 

Comments

Popular posts from this blog

javascript - Unusual behaviour when drawing lots of images onto a large canvas -

how can i manage url using .htaccess in php? -

javascript - Chart.js - setting tooltip z-index -