angular-forms

Angular Forms: How to avoid multiple NgIf divs for validation error messages?

会有一股神秘感。 提交于 2021-01-27 15:56:17
问题 I would like to simplify the code below: <div *ngIf="form1.errors?.checkDate && (form1.touched || form1.dirty)" class="cross-validation-error-message alert alert-danger"> Date can't be in the future. </div> <div *ngIf="form1.errors?.notAfterDate && (form1.touched || form1.dirty)" class="cross-validation-error-message alert alert-danger"> Birth Date must be after 1/1/1800. </div> It should have only 1 div *ngif and pass the error message as a value instead of hardcoding or use a ngFor ? Any

Angular - Objects as Select Option Values

本小妞迷上赌 提交于 2021-01-21 12:33:34
问题 I have a form with various select boxes which use objects as the value: <mat-option [value]="object"> Which works great when I am creating new records via the form. Now when I am editing records, I run into the problem that the object in the mat-select-option is not the "same" object that I get from my rest service, so my select boxes have no option selected when editing the record. Is it possible to tell the select-box widget to match on object.id when deciding what option is selected? I

Angular Subscribe valuechanges in formarray in form group

非 Y 不嫁゛ 提交于 2021-01-05 07:41:56
问题 I'm angular8 and I have a form array inside of form group but I want to detect new changes of a certain input. ngOnInit(): void { this.makeForm = this.fb.group({ year:['', Validators.required], amount:['', Validators.required], desc:['', Validators.required], details: new FormArray([ this.det(), ]) }) det(){ return new FormGroup({ requestfor : new FormControl(''), remarks : new FormControl(''), // file_id : new FormControl(''), })} I have to check the data that every value changes in

ngTemplateOutlet - Angular 5 nested template driven form

柔情痞子 提交于 2021-01-04 10:36:14
问题 I have a ng-template which is being passed on from one of my component and i have a placeholder to accept the passed on ng-template onto my component as shown below in ngTemplateOutlet. <div> <form novalidate #myForm="ngForm"> <ng-container> <ng-template [ngTemplateOutlet]="myTemplate"> </ng-template> </ng-container> </form> </div> <!-- this template i am passing it from one of my other components --> <ng-template #myTemplate> <input type="text" name="myInput" placeholder="Input" [(ngModel)]=