Skip to content

Instantly share code, notes, and snippets.

@LironHazan
Created October 15, 2018 09:45
Show Gist options
  • Save LironHazan/40370c757858d0286dbeb2ea89507ff6 to your computer and use it in GitHub Desktop.
Save LironHazan/40370c757858d0286dbeb2ea89507ff6 to your computer and use it in GitHub Desktop.
reactive-forms-angular
// 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