2016-03-05 17:53:34 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// #docregion
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { Injectable }   from '@angular/core';
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-18 12:00:04 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { FormControl, FormGroup, Validators } from '@angular/forms';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { QuestionBase } from './question-base';
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-05 17:53:34 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								@Injectable()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								export class QuestionControlService {
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-18 12:00:04 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  constructor() { }
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-05 17:53:34 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-18 12:00:04 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  toFormGroup(questions: QuestionBase<any>[] ) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let group: any = {};
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-05 17:53:34 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    questions.forEach(question => {
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-18 12:00:04 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      group[question.key] = question.required ? new FormControl(question.value || '', Validators.required)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                              : new FormControl(question.value || '');
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-05 17:53:34 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-18 12:00:04 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return new FormGroup(group);
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-05 17:53:34 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |