Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-list equivalent in Angular 2

Having a difficulty finding documentation on this, but in Angular 1 you could do:

<textarea ng-model="name" ng-list=","></textarea>

Then on input, if you were to enter "Hello, world!" name would be an array of ["Hello", "world!"].

My goal is to use ng-list with the HTML entity &#10; for breaking a textarea by line into an array. See example from docs.

Is there an equivalent of this in Angular 2?

like image 999
Carl Reid Avatar asked Dec 01 '16 08:12

Carl Reid


Video Answer


1 Answers

Could not find native solution, but you can use (ngModelChange) and then get the parsed value like this:

  parseTextArea() {
     this.textareaParsed = this.textarea.split("\n");
  }

and in your template:

<textarea [(ngModel)]="textarea" (ngModelChange)="parseTextArea()"></textarea>

See this plunker: textarea example (in Chrome, IE has some issues with config.js...)

like image 53
Petr Adam Avatar answered Nov 03 '22 00:11

Petr Adam