1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| # 子组件 注意看【重点】 @Component({ selector: 'hc-form-department', templateUrl: './form-department.component.html', styles: [ ], //【重点1】 providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: FormDepartmentComponent, multi: true }] })
export class FormDepartmentComponent implements OnInit,ControlValueAccessor {
form: FormGroup; formChangeFn;
departmentList:[{ deptNum:'', deptName:'' }];
nodes = [];
constructor( public i18n: I18NService, private fb: FormBuilder, private http: HttpClientService, private convertTree: ConvertTreeService, private modal: ModalHelper ) { this.form = fb.group({ deptNum: [null], }); }
ngOnInit(): void { this.getAllDepartment(); }
addDepartment(){ this.modal.createStatic(UserDepartmentEditComponent, {record: {isEdit: false, key: 0}}, { size: 'md'} ).subscribe((res) => { this.getAllDepartment(); }); }
getAllDepartment(){}
onChange(data){ this.formChangeFn(data); } registerOnChange(fn: any): void { this.formChangeFn = fn; }
registerOnTouched(fn: any): void { }
writeValue(value: any): void { if(value){ this.deptNum = value; } }
get deptNum() { return this.form.controls.deptNum; }
set deptNum(data) { this.form.controls.deptNum.setValue(data); } checkValidity() { this.deptNum.markAsDirty(); this.deptNum.updateValueAndValidity(); }
}
|