angular - 重置 Angular react 形式排除特定领域

标签 angular typescript angular-reactive-forms

引用(https://stackoverflow.com/questions/50197347/how-to-reset-only-specific-fields-of-form-in-angular-5) ,我有表单中有 20 个字段,如果用户单击重置选项我需要重置表单排除 2 个字段,如果我使用 this.form.reset() 意味着它重置所有内容,感谢任何帮助

最佳答案

只看onReset() 方法。此代码将重置除 namedescription 字段之外的所有内容

formGroup: FormGroup = /* init the formGroup... */

onReset() {
    this.formGroup.reset({
        name: this.formGroup.get('email').value, 
        description: this.formGroup.get('description').value
    });
}

Stackblitz repro

关于angular - 重置 Angular react 形式排除特定领域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54783220/

相关文章:

angular - Angular Reactive Form 的深拷贝?

javascript - AngularJS 发布查询

TypeScript:返回与参数相同的类型

如果相关表单组无效,Angular 7 和表单数组会禁用表单组的按钮,并给出未定义的错误

typescript - Angular 6 复选框过滤器

typescript - CORS 策略 : No 'Access-Control-Allow-Origin' header is present on the requested resource in ionic 2

angular - FormBuilder 组已被验证器弃用

javascript - typescript 返回对象或数组错误

Angular 2 - 来自 JSON 数据的动态路由

javascript - 使用 MeteorJS Collection 和 Angular 2 显示数据