【问题标题】:push properties in array from dropdown and input - Angular 2从下拉列表和输入中推送数组中的属性 - Angular 2
【发布时间】:2018-08-30 16:51:46
【问题描述】:

我有一排输入字段和下拉菜单。我可以通过单击“添加行”按钮生成新行。我通过“i of index”进行管理,以获取该行中每个输入的值,但我无法为下拉列表执行此操作(当我从下拉列表中选择项目时也会出错)。当您填写输入并从下拉列表中选择时,您可以在按下按钮后在控制台日志中看到结果。

Plunker:Plunker

console.log 示例:

(2) [{…}, {…}]

0 : {名称:“A”,数据:“123”,数字:“”,字符:“”} 1 : {名称:“B”,数据:“123”,数字:“”,字符:“”}

或许还有其他的解决方案……

【问题讨论】:

    标签: arrays angular input


    【解决方案1】:

    为什么不直接使用 ng 模型属性呢?
    Something like in this plunkr

    <select [(ngModel)]="this.properties[i].num">
      <option selected disabled>Select type</option>
      <option *ngFor="let type of numberTypes">{{type}}</option>
    </select>
    
    <select [(ngModel)]="this.properties[i].char">
      <option selected disabled>Select type</option>
      <option *ngFor="let type of charTypes">{{type}}</option>
    </select>
    

    【讨论】:

    • 当然...任何一分钟,都有时间限制 ;)
    • 对不起,我不知道!
    猜你喜欢
    • 2018-07-02
    • 2017-06-01
    • 1970-01-01
    • 2017-03-23
    • 1970-01-01
    • 1970-01-01
    • 2017-08-30
    • 2011-01-22
    • 1970-01-01
    相关资源
    最近更新 更多