我们可以检查 angular 反应形式的形式是否被禁用吗?

can we check form is disabled or not in angular reactive form?

我在 angular9 中使用反应式表单进行表单验证。现在我需要隐藏提交按钮,它是这个表单之外的百分比,如果表单被禁用(表单中的所有字段都被禁用)。 formgroup 中是否有任何变量或方法百分比可以实现此目的?

formValidationConfig() {
        this.userDataUpdateForm = new FormBuilder().group({
            language: [''],
            firstname: ['', [Validators.required, Validators.minLength(3), Validators.maxLength(20), Validators.pattern('^(?!_)^[a-zA-Z0-9_]*$')]],
            lastname: ['', Validators.pattern('^(?!_)^[a-zA-Z0-9_]*$')],
            gender: ['', Validators.required],
            pan: [''],
            mobile: ['', [Validators.minLength(10), Validators.maxLength(10)]],
            email: ['', Validators.email],
            address: [''],
            pincode: [''],
            city: [''],
            state: [''],
            country: [''],
            day: ['', Validators.required],
            month: ['' , Validators.required],
            year: ['', Validators.required],
            otp: ['']
        });
    }

    disableFields() {
        try {
            if (this.userProfileData.pref_lang.length > 0) { this.f.language.disable(); }
            if (this.userProfileData.firstname?.length > 0) { this.f.firstname.disable(); }
            if (this.userProfileData.lastname?.length > 0) { this.f.lastname.disable(); }
            if (this.userProfileData.gender?.length > 0) { this.f.gender.disable(); }
            if (this.userProfileData.pan_number.length > 0) { this.f.pan.disable(); }
            if (this.userProfileData.language?.length > 0) { this.f.language.disable(); }
            if (this.userProfileData?.email_status === 'active') { this.f.email.disable(); }
            if (this.userProfileData?.mobile_verification === '1') { this.f.mobile.disable(); }
            if (this.userProfileData?.address?.length > 0) { this.f.address.disable(); }
            if (this.userProfileData?.pincode?.length > 0) { this.f.pincode.disable(); }
            if (this.userProfileData?.city?.length > 0) { this.f.city.disable(); }
            if (this.userProfileData?.state_name?.length > 0) { this.f.state.disable(); }
            if (this.userProfileData?.country?.length > 0) { this.f.country.disable(); }
            if (this.userProfileData.day) { this.f.day.disable(); }
            if (this.userProfileData.month ) { this.f.month.disable(); }
            if (this.userProfileData.year) { this.f.year.disable(); }
        } catch (error) { console.log('Profile disabled error', error); }
        console.log('disabled obj--->');
    }

在不知道你具体情况的情况下,你可以尝试这样的操作:

<button *ngIf="!form.disabled">Save</button>

表单组已禁用 属性,如果表单组设置为禁用,则为真。