Created
October 15, 2018 09:45
-
-
Save LironHazan/40370c757858d0286dbeb2ea89507ff6 to your computer and use it in GitHub Desktop.
reactive-forms-angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// component part | |
// 1. declare formgroup which contains wanted form control | |
public securityForm: FormGroup = new FormGroup({ | |
classificationItem: new FormControl() | |
}); | |
private classification: ClassificationModel; | |
private fb: FormBuilder; | |
ngOnInit() { | |
this.classification = getClassification(); | |
// 2. build form group using the builder and init item value | |
this.securityForm = this.fb.group({ | |
classificationItem: [this.classification] | |
}); | |
} | |
// template part | |
<form [formGroup]="securityForm" id="securityForm"> | |
<div class="field-container classification"> | |
<label>Classification</label> | |
<p-dropdown | |
class="sec-item" | |
[options]="classifications" | |
(onChange)="classificationSelectedChanged($event)" | |
formControlName="classificationItem" | |
optionLabel="label"> | |
</p-dropdown> | |
</div> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment