Angular 2 中的 ng-list 等价物 [英] ng-list equivalent in Angular 2
问题描述
很难找到这方面的文档,但在 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 实体
将 textarea
按行分解成数组.请参阅文档中的示例.
My goal is to use ng-list
with the HTML entity
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屋!