【发布时间】:2021-02-11 03:20:46
【问题描述】:
我正在尝试实现一个编辑表单,该表单显示它从数据库中获取的值数据,但问题是当我尝试将formGroup 与formBuilder 一起使用时,我无法将我的@INPUT 数据放入构造函数中我得到未定义的数据。
如何在 formbuilder 构造函数中使用@input 数据?
export class EditModalComponent implements OnInit {
checkoutForm;
@Input() product //this is the data from the father component
closeResult = '';
ngOnInit() {
}
constructor(private modalService: NgbModal,
private formBuilder: FormBuilder) {
this.checkoutForm = this.formBuilder.group({
imageURL: this.product.imageURL,// i get undefined
name: this.product.name,// i get undefined
category: this.product.category,// i get undefined
price: this.product.price,// i get undefined
});
}
【问题讨论】: