检索输入字段设置值

时间:2018-06-21 16:31:32

标签: angular

我正在使用Angular5。我为输入字段设置了默认的form(在表单加载时)。但是,在尝试提交此先前分配的默认值value的{​​{1}}提交时,它返回一个空字符串。

我该如何解决?

<input formControlName="age" type="text" id="ageid"  class="form-item" value="{{student.age}}">

这是我尝试将值检索为的方式:

console.log("result " + JSON.stringify(this.studentform.value.age));

更新

this.studentform = this.fb.group({
  age: ['', Validators.required]
}, { });

1 个答案:

答案 0 :(得分:1)

尝试使用以下代码:

console.log("result " + JSON.stringify(this.studentform.controls.age.value));

即使尝试通过打印this.studentform对象来查看控件的状态

相关问题