Last active
October 17, 2018 15:55
-
-
Save ssuperczynski/9db044a0ae69fa8feb5fb9f82c99f6ce to your computer and use it in GitHub Desktop.
This file contains 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
import { OnInit } from '@angular/core'; | |
import { FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; | |
export interface CommonAddress { | |
id: number; | |
name: string; | |
} | |
export const FORM_PARAMS = { | |
supervisors: 'supervisors', | |
}; | |
export class RecruitmentEditComponent implements OnInit { | |
public recruitmentForm: FormGroup; | |
constructor(private fb: FormBuilder) {} | |
ngOnInit() { | |
this.recruitmentForm = this.fb.group({ | |
supervisors: this.fb.array([]), | |
}); | |
} | |
get supervisors(): FormArray { | |
return this.recruitmentForm.get(FORM_PARAMS.supervisors) as FormArray; | |
} | |
// You will not get any error if `_.id type is not equal to item.id` | |
selectSupervisor(item: any) { | |
const defined = this.supervisors.getRawValue().some(_ => _.id === item.id); | |
if (!defined) { | |
this.supervisors.push(new FormControl({ | |
id: item.id, | |
name: item.name, | |
})); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment