Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

angularjs - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

and in your template:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...