Angular 2 中的 ng-list 等价物 [英] ng-list equivalent in Angular 2

查看:37
本文介绍了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?

推荐答案

Could not find native solution, but you can use (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>

查看此 plunker:textarea 示例(在 Chrome 中,IE 有一些config.js 的问题...)

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

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

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