我只希望显示myObject中控件名形式的信息。
this.form = this.FormBuilder.group({
lname:[null, Validators.compose([Validators.required])],
fname: [null, Validators.compose([Validators.required])],
phone:[null, Validators.compose([Validators.required])],
id:[null, Validators.compose([Validators.required])],
age:[null, Validators.compose([Validators.required])],
});
我只想显示该对象中的值
this.myObject = {0:"id", 1:"fname", 2:"lname"}
for (var val in this.myObject ) {
console.log(this.form.value.myObject [val] )
}
答案 0 :(得分:1)
您可以尝试:
for(let item in this.myObject){
console.log(this.form.controls[this.myObject[item]].value)
console.log(this.form.get(this.myObject[item]).value) // or
console.log(this.form.value[this.myObject[item]]) // or
}
答案 1 :(得分:0)
内部for循环:
this.form.get(val).value
FormGroup.get(controllerName: string)
返回AbstractController