【问题标题】:update number field value in nested angular 2 component更新嵌套 Angular 2 组件中的数字字段值
【发布时间】:2017-03-25 15:17:01
【问题描述】:

我有一个嵌套/子表单组。它有一个数字字段,需要通过单击按钮来更新。我可以更新值本身,但无法更新字段。

我该如何解决?

这里是 plnkr https://plnkr.co/edit/ZN3cGHHRNvx7348x1PSm?p=preview

increment() {
  this.number++;
  this.adressForm.value.age = this.number++;

}

提前致谢。

【问题讨论】:

  • 对不起,我看了你的 plunkr 还是没明白这个问题。您的 plunkr 没有按钮,并且表单值在输入时会更新数字。您需要进一步澄清您的问题。
  • 字段下方不是<button><span><button>重新加载plunkr

标签: javascript forms angular components


【解决方案1】:

AddressComponent 中将您的代码更改为

increment() {
  let currentAgeValue : number = this.adressForm.controls.age.value;
  this.adressForm.controls.age.setValue(currentAgeValue + 1);
}

工作分叉Plunker

【讨论】:

    猜你喜欢
    • 2018-01-14
    • 2017-07-05
    • 2012-03-25
    • 2020-05-08
    • 2021-09-19
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 2023-01-27
    相关资源
    最近更新 更多