angular2-formbuilder

How to programmatically change pristine property in angular 2 form without ng-model

大兔子大兔子 提交于 2019-12-22 07:56:11
问题 I'm new in Angular 2 framework. I appreciate any help. I have usual component in angular 2: import {FORM_DIRECTIVES, FormBuilder, Validators} from 'angular2/common'; export class TestComponent { public values = ['value1', 'value2', 'value3', 'value4']; } Then I'm injecting FormBuilder into the constructor function: @Inject(FormBuilder) public fb HTML contain next markup: <input [(ngModel)]="formData.title" type="text" class="form-control" ngControl="title"> Title and description works great.

Angular - Reactive Forms - How to pass an object to a FormGroup with a class and validators

╄→гoц情女王★ 提交于 2019-12-21 19:59:46
问题 I have a large form to create and decided to use the reactive form feature for ease of use. However, I am facing a few challenges that might be obvious and looking for help. Below are two cases that yield the same outcome with the exception of the validation. The createFormWithValidation() method specifics every control and it's associated validators. The createFromPassingObject() method creates the same form using just the this.party object but without the added validators. My goal is to

How to iterate form array(array in array in array) in angular2 reactive forms?

。_饼干妹妹 提交于 2019-12-19 09:40:22
问题 I tried to Iterate formArray several times, This is plunker link for this case https://plnkr.co/edit/4kiJF7cL5VKwn3KnvjvK?p=preview i want out put like this plunk https://plnkr.co/edit/zg6nbFULl0WlTZ1sVn5h?p=preview This is my scenario [ { "id": 1, "legend": "businessModule", "group": [ { "id": 1, "permission": { "controleType": "ff", "id": 2, "key": "create Business" }, "roles": [ { "id": 1, "name": "self" }, { "id": 2, "name": "other" } ] }, { "id": 1, "permission": { "controleType": "ff",

Two way binding in reactive forms

喜你入骨 提交于 2019-12-18 13:52:14
问题 Using Angular 2, two-way binding is easy in template-driven forms - you just use the banana box syntax. How would you replicate this behavior in a model-driven form? For example, here is a standard reactive form. Let's pretend it's much more complicated than it looks, with lots and lots of various inputs and business logic, and therefore more appropriate for a model-driven approach than a template-driven approach. export class ExampleModel { public name: string; // ... lots of other inputs }

Two way binding in reactive forms

拥有回忆 提交于 2019-12-18 13:52:05
问题 Using Angular 2, two-way binding is easy in template-driven forms - you just use the banana box syntax. How would you replicate this behavior in a model-driven form? For example, here is a standard reactive form. Let's pretend it's much more complicated than it looks, with lots and lots of various inputs and business logic, and therefore more appropriate for a model-driven approach than a template-driven approach. export class ExampleModel { public name: string; // ... lots of other inputs }

onsubmit return all the rows input values angular 2

一笑奈何 提交于 2019-12-14 03:18:10
问题 I'm new to angular 2. I have a table, which on click of 'add consignment' option, it adds a new row with serial number and multiple input slots. Now on adding more consignments (which adds more rows of multiple input slots in table), and entering information to all these rows and submitting, only the values of last row is being returned. Can someone please tell me how to return the values of all the multiple input rows from the table as one single object? Thank you. Below is my code: Template

Angular: Bind date picked from bootstrap-datepicker to underlying ngModel or formControlName

大兔子大兔子 提交于 2019-12-13 03:33:40
问题 I'm using bootstrap-datepicker in my Angular project by creating it as a directive. Below is my code. HTML: <input [datepicker]="datepickerConfig" readonly ngModel name="requestedDate" class="form-control" id="requestedDate" type="text"> Datepicker config in component: datepickerConfig = { format: 'dd-M-yyyy' }; Directive: @Directive({ selector: '[datepicker]' }) export class DatepickerDirective implements OnInit { @Input() datepicker; constructor(private el: ElementRef) { } ngOnInit() { $

Angular 2 form status is always invalid with custom validation for ng-select control

自作多情 提交于 2019-12-12 13:07:52
问题 I have used validation in user info form as below. this.userInfoForm = this.fb.group({ retrieveId: [''], customerName: [[],[UtilityService.checkMinLength(3, 50)]], }); I have created below service to check validation @Injectable() export class UtilityService { static checkMinLength(min: number, max: number): ValidatorFn { return (c: AbstractControl) => { if (c.value && c.value != undefined) { return { 'checkMinLength': c.value.some((a) => { if (a.itemName.length < min || a.itemName.length >

How to populate a form with array of data in Angular2?

本小妞迷上赌 提交于 2019-12-12 09:59:09
问题 The SO question below helped me setup a formbuilder, proper validation, and a dynamic set of input fields from a formBuilder Array. How to assign and validate arrays to forms in Angular2 Note this solution code http://plnkr.co/edit/YoqdBEo0MihaxdhHH1FV?p=preview Everything works great on a new form, but I get stuck when trying to populate said form from the database. I'm using the following code and initialValue has multiple emails saved from this form in a previous transaction. All my other

How to add more input fields using a button - Angular 2 dynamic forms

一世执手 提交于 2019-12-12 08:09:23
问题 So I used the guide here: https://angular.io/docs/ts/latest/cookbook/dynamic-form.html I need to add more fields to an existing field. I've made something that works, but it's clunky and it resets the form when I hit it. Code below: In dynamic-form.component.ts: add_textbox() { this.questions.push(this.questionService.create_textbox({key: "test", label: "Test"})); console.log(this.questions); this.form = this.qcs.toFormGroup(this.questions); } In question.service.ts create_textbox({key, value