Reputation: 94
I am Using below code to create a form and make it readOnly, I am new to angular
createForm() {
this.comapnyIdentificationForm = this.fb.group({
businessName: ['', Validators.required ],
adressPrimary: '',
adressSecondary: '',
city:'',
state: '',
zipCode: '',
country: '',
companyPhone: '',
DUNS: ''
});
this.comapnyIdentificationForm.disable();
}
I need to make it enabled and post edited data back to Json :
<button type="button" (click)="EditData()" class="btn modal-btn btn-default">Edit</button>
Upvotes: 0
Views: 1042
Reputation: 3730
Just use following code to enable your form .
this.comapnyIdentificationForm.enable();
To get a json object. Use following code:
this.comapnyIdentificationForm.value;
To fill-up your form with backend data use following code: this.comapnyIdentificationForm.patchValue(jsonData);
Upvotes: 1
Reputation: 57981
You can use a directive too
@Directive({
selector: '[enableControl]'
})
export class EnableControlDirective {
@Input() set enableControl( condition : boolean ) {
if (condition)
this.ngControl.control.enable();
else
this.ngControl.control.disable();
}
constructor(private ngControl : NgControl ) {}
}
//use
<input class="form-control " [enableControl]="condition">
Upvotes: 1