angular-reactive-forms

Pass image from FileReader to form input in Angular 6

本小妞迷上赌 提交于 2019-11-30 17:15:57
问题 I try to create an UI where there is a form with a couple of text fields, a input type="file" and a div that you can drop images to upload with the rest of the form. My goal / logic use the same div to either drop an image or click on it and open the folder explorer like the input type="file" behaves. Enabling clicking makes sense in small screens where it is practically impossible to "drag and drop". And since there is already a input type="file" in the form there is no reason to take the

Initialize Form Array With existing array in angular reactive form

这一生的挚爱 提交于 2019-11-30 09:54:00
I have an dynamic array of department list fetched from server. I want to push that array to form array on initialization, basically i want to show checkboxes based on department name or id in array. I know how to push an empty array in reactive forms.but how to initialize with an existing array.Actually its an update/edit Component departmentList:any=[]; //array contains all departments SelectedDeptList:any=[]; //fetched from db , selected departments userForm: FormGroup; this.userForm = this.fb.group({ //fb form builder 'phone': [null], 'departmentList': this.fb.array([this.createDepartment(

Can I access to formControl of my custom ControlValueAccessor in Angular 2+?

落花浮王杯 提交于 2019-11-30 08:28:47
I would like to create a custom form element with ControlValueAccessor interface in Angular 2+. This element would be a wrapper over a <select> . Is it possible to propagate the formControl properties to the wrapped element? In my case, the validation state is not getting propagated to nested select as you can see on the attached screenshot. My component is available as following: const OPTIONS_VALUE_ACCESSOR: any = { multi: true, provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => OptionsComponent) }; @Component({ providers: [OPTIONS_VALUE_ACCESSOR], selector: 'inf-select[name]',

Angular 4 - Reactive Forms - select item in a list from object not referenced in this list - trackby issue?

◇◆丶佛笑我妖孽 提交于 2019-11-30 07:14:44
问题 I am converting Angular 1.6 code to Angular 4 and I have an issue with a list of elements. The code in Angular 1.6 is: <select ng-model="$ctrl.level" ng-options="item as item.label for item in $ctrl.referentiel.levels | orderBy : 'index' track by item.id" id="childLevel" name="childLevel" class="size-xl" > <option value="">Select</option> </select> The object level is not referenced in my list because this list is loaded using the object referentiel.levels. But the matching between the

Requiring a checkbox to be checked

巧了我就是萌 提交于 2019-11-30 06:04:24
I want a button to be disabled until a checkbox has been checked using a FormBuilder for Angular. I don't want to explicitly check the value of the checkbox and would prefer to use a validator so that I can simply check form.valid . In both validation cases below the checkbox is interface ValidationResult { [key:string]:boolean; } export class CheckboxValidator { static checked(control:Control) { return { "checked": control.value }; } } @Component({ selector: 'my-form', directives: [FORM_DIRECTIVES], template: ` <form [ngFormModel]="form" (ngSubmit)="onSubmit(form.value)"> <input type=

angular 5 template forms detect change of form validity status

落爺英雄遲暮 提交于 2019-11-30 04:47:20
are reactive forms the way to go in order to have a component that can listen for changes in the validity status of the form it contains and execute some compoment's methods? It is easy to disable the submit button in the template using templateRef like [disabled]="#myForm.invalid" , but this does not involve the component's logic. Looking at template forms' doc I did not find a way Sravan If you want to get only the status and not the value you can use statusChanges : export class Component { @ViewChild('myForm') myForm; this.myForm.statusChanges.subscribe( result => console.log(result) ); }

touched and valid using reactive forms in Angular

最后都变了- 提交于 2019-11-29 18:28:18
问题 How can i use the touched and valid properties using reactive forms in angular 4. I've used in template driven forms and you can just put this <span class="text-muted" *ngIf="!fname.valid && fname.touched"> Please enter a valid first name</span> below the input field. I've also learned that reactive forms would be better since you have to write the logic in the component.ts. So i want it to implement in the reactive form and i'm stuck on how to use the touched and valid properties. html <form

How to set value to form control in Reactive Forms in Angular

坚强是说给别人听的谎言 提交于 2019-11-29 17:35:07
问题 Hi Everyone I'm new to angular. Actually, I'm trying to subscribe data from a service and that data, I'm passing to form control of mine from (example, it's like an edit form). import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators, FormArray, FormControl } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; import { QuestionService } from '../shared/question.service'; @Component({ selector: 'app-update-que', templateUrl: '.

Add item in dynamic reactive form in Angular

╄→гoц情女王★ 提交于 2019-11-29 11:51:02
I am trying to build a nested reactive form in Angular 5. I am able to push items at one level, but unable to push item at second level. ngOnInit() { this.orderForm = this.formBuilder.group({ customerName: '', email: '', items: this.formBuilder.array([this.createItem()]) }); } createItem(): FormGroup { return this.formBuilder.group({ name: 'a', description: 'b', price: 'c', //subItems: this.formBuilder.array([this.createSubItem()]) }); } //createSubItem(): FormGroup { //return this.formBuilder.group({ //subname: 'abc' //}); //} addItem(): void { this.items = this.orderForm.get('items') as

Initialize Form Array With existing array in angular reactive form

本小妞迷上赌 提交于 2019-11-29 09:53:59
问题 I have an dynamic array of department list fetched from server. I want to push that array to form array on initialization, basically i want to show checkboxes based on department name or id in array. I know how to push an empty array in reactive forms.but how to initialize with an existing array.Actually its an update/edit Component departmentList:any=[]; //array contains all departments SelectedDeptList:any=[]; //fetched from db , selected departments userForm: FormGroup; this.userForm =