gpt4 book ai didi

Angular 6 : Cannot read property 'reset' of undefined

转载 作者:搜寻专家 更新时间:2023-10-30 22:03:56 24 4
gpt4 key购买 nike

我在我的方法中使用重置时收到错误消息。我试图在保存更改后重置表单,但收到此错误:

enter image description here

这是我的方法:

  @ViewChild('editFrom')
editForm: NgForm;
constructor(
private route: ActivatedRoute,
private alertify: AlertifyService
) {}

ngOnInit() {

}
updateUser() {
console.log(this.user);
this.alertify.success('Profile Updated Successfully');
this.editForm.reset(this.user);
}
}

此 Html 表单:

<form #editForm="ngForm" id="editForm" (ngSubmit)="updateUser()">
<h4>Description</h4>
<textarea name="introduction" rows="6" class="form-control" [(ngModel)]="user.introduction"></textarea>
<h4>Looking For</h4>
<textarea name="lookingFor" rows="6" class="form-control" [(ngModel)]="user.lookingFor"></textarea>
<h4>Interest </h4>
<textarea name="interests" rows="6" class="form-control" [(ngModel)]="user.interest"></textarea>
<h4>Location Details:</h4>
<div class="form-inline">
<label for="city">City:</label>
<input class="form-control" type="text" name="city" [(ngModel)]="user.city">
<label for="country">Country:</label>
<input class="form-control" type="text" name="country" [(ngModel)]="user.country">
</div>
</form>

最佳答案

问题是你用了<form #editForm="ngForm" id="editForm" (ngSubmit)="updateUser()">在 HTML 文件中

来到您正在使用的 .ts 文件 @ViewChild('editFrom')它应该是@ViewChild('editForm')

关于 Angular 6 : Cannot read property 'reset' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53023945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com