Angular 2中的ng-list等效项 [英] ng-list equivalent in Angular 2

查看:88
本文介绍了Angular 2中的ng-list等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很难找到有关此文档的信息,但是在Angular 1中,您可以执行以下操作:

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

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

然后输入,如果您要输入"Hello,world!" name将是["Hello", "world!"]的数组.

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

我的目标是将ng-list与HTML实体&#10;一起使用,以将textarea按行拆分为一个数组.请参阅文档中的示例.

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.

Angular 2中有与之等效的东西吗?

Is there an equivalent of this in Angular 2?

推荐答案

找不到本机解决方案,但是您可以使用(ngModelChange),然后像这样获取解析后的值:

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");
  }

并在您的模板中:

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

请参阅以下示例:文本区域示例(在Chrome中,具有一些config.js问题 ...)

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

这篇关于Angular 2中的ng-list等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆