简体   繁体   English

Angular 2中的ng-list等效项

[英]ng-list equivalent in Angular 2

Having a difficulty finding documentation on this, but in Angular 1 you could do: 很难找到关于此的文档,但是在Angular 1中,您可以执行以下操作:

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

Then on input, if you were to enter "Hello, world!" 然后在输入时,如果要输入“ Hello,world!” name would be an array of ["Hello", "world!"] . name将是["Hello", "world!"]的数组。

My goal is to use ng-list with the HTML entity &#10; 我的目标是将ng-list与HTML实体&#10; for breaking a textarea by line into an array. 用于将textarea按行分成数组。 See example from docs . 请参阅docs中的示例

Is there an equivalent of this in Angular 2? 在Angular 2中有与此等效的功能吗?

Could not find native solution, but you can use (ngModelChange) and then get the parsed value like this: 找不到本机解决方案,但是您可以使用(ngModelChange) ,然后像这样获取解析后的值:

  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 ...) 参见以下示例: textarea示例在Chrome中,IE的config.js存在一些问题 ...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM