import { ChangeDetectionStrategy , Component , Input } from '@angular/core' ; import { DynamicFormBuilder , DynamicFormGroup } from 'ngx-dynamic-form-builder' ; import { ExpUser } from '../../shared/models/exp-user' ; @ Component ( { selector : 'exp-user-panel' , templateUrl : './exp-user-panel.component.html' , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class ExpUserPanelComponent { form : DynamicFormGroup < ExpUser > ; @ Input ( ) item = new ExpUser ( { username : 'admin' , isStaff : true , id : 1 , isSuperuser : true , dateOfBirth : '1985-05-11T01:00:00Z' , password : 'secretpassword' , email : 'admin@site15.ru' , department : { id : 2 , name : 'department 1' , company : { id : 3 , name : 'company 2' , regionNum : 1 , } , } , } ) ; fb = new DynamicFormBuilder ( ) ; savedItem ? : Object ; constructor ( ) { this . form = this . fb . group ( ExpUser , { classValidatorOptions : { groups : [ 'user' ] , } , } ) ; } onLoadClick ( ) { this . savedItem = undefined ; this . form . object = this . item ; this . form . validateAllFormFields ( ) ; } onClearClick ( ) { this . savedItem = undefined ; this . form . object = new ExpUser ( ) ; this . form . validateAllFormFields ( ) ; } onSaveClick ( ) { this . form . validateAllFormFields ( ) ; if ( this . form . valid ) { this . savedItem = this . form . json ; } else { this . savedItem = undefined ; } } }