angular2-forms

Angular 2 - form group component

旧城冷巷雨未停 提交于 2019-12-10 02:21:20
问题 I'm trying to build a data-driven form, with inputs coming from another component, like this: <form [formGroup]="signupForm" (ngSubmit)="onSubmit()"> <app-form-group [name]="name"></app-form-group> <app-form-group [name]="email"></app-form-group> <app-form-group [name]="other"></app-form-group> </form> The app-form-group component will look something like this: <div class="form-group"> <label class="col-md-2 control-label">{{Name}}</label> <div class="col-md-9"> <input class="form-control"

Angular2 Reactive forms - Set default value for form fields with dropdown

 ̄綄美尐妖づ 提交于 2019-12-09 14:03:28
问题 How can I set the default value for all forms fields in angular 2 reactive forms? Here is the plnkr to reproduce the issue Below code does not update dropdown values as it has an object associated with it. Note: Here I need to set the default value for all form fields with the response received from Backend API. Component.html <form [formGroup]="myForm" novalidate (ngSubmit)="save(myForm.value, myForm.valid)"> <div class="form-group"> <label>Country:</label> <select formControlName="country">

How to correctly import FormGroup in NgModule in Angular 2

丶灬走出姿态 提交于 2019-12-09 07:59:23
问题 I try to import FromGroup , FormBuilder and FormControl to my CustomModule : import { FormsModule, FormGroup } from '@angular/forms'; @NgModule({ imports: [ FormsModule, FormGroup ] }) But it throws an error: EXCEPTION: Uncaught (in promise): Error: Unexpected value 'FormGroup' imported by the module 'CustomModule' If i only import FormsModule it works fine though. Any ideas? 回答1: You can't add FormGroup to module's imports, just import it in the component in which you want to use FormGroup .

Radio button for boolean property

家住魔仙堡 提交于 2019-12-09 07:36:25
问题 I have a simple boolean property valid in my object document and need to bind it to radio-inputs. This is what i have so far: <input type="radio" name="valid" id="validTrue" (click)="document.valid = true" [checked]="document.valid"/> <input type="radio" name="valid" id="validFalse" (click)="document.valid = false" [checked]="!document.valid"/> At least setting the property on click works but its state is no displayed by the radio-inputs. Looking in the developer console of my browser i found

Angular 2 form validation, minLength validator is not working

无人久伴 提交于 2019-12-09 07:32:54
问题 I have following Angular 2 form: <register> <form [ngFormModel] = "registrationForm"> <div class = "form-group"> <label class = "control-label" for="email">Email</label> <input class = "form-control" type="email" id="email" ngControl="email" #email="ngForm"> </div> <div *ngIf = "email.touched && email.errors"> <div *ngIf = "!email.errors.required && email.errors.underscoreNotFound" class = "alert alert-danger"> <span>Underscore is required</span> </div> <div *ngIf = "email.errors.required"

How to build nested array by using angular2 Reactive forms?

◇◆丶佛笑我妖孽 提交于 2019-12-09 07:12:56
问题 I have an array like [ { "PermissionRoleModule":{ "id":1, "legend":"businessModule", "group":[ { "PermissionRoleGroup":{ "id":1, "permission":{ "controleType":"ff", "id":2, "key":"create Business" }, "roles":[ { "id":1, "name":"self" }, { "id":2, "name":"other" } ] } }, { "PermissionRoleGroup":{ "id":1, "permission":{ "controleType":"ff", "id":2, "key":"edit business" }, "roles":[ { "id":1, "name":"self" }, { "id":2, "name":"other" } ] } } ] } }, { "PermissionRoleModule":{ "id":2, "legend":

use formControlName with something like <span>

喜你入骨 提交于 2019-12-08 19:10:59
问题 I have a dynamic form which shows multiple datasets I've got via REST. The user will edit this dataset and then later just submit it to get it sent back to the server. The form is built dynamically with FormBuilder.array() and looped through via formArrayName + *ngFor in my template. One property of each dataset is a "last updated" information I want to display along with the editable data in my form. Right now I use an <input> field with disabled attribute - but this looks kinda ugly. When I

How to do a global search in angular 2?

帅比萌擦擦* 提交于 2019-12-08 17:18:52
问题 I'm a new developper in angular2 and I want to do a global search in an array of json objects. For example, this array : invoiceList = [ { invoiceNumber: 1234, invoiceSupplier: "test", invoiceStatus: "Import error", invoiceCategory: "invoice with GR", date: "22/01/2017", amount : 134527 }, ... ]; And I want to do my search like that : The problem and the difficulty here is that : I want to search depending only on some values (ex : status, supplier name, number...) and display OTHER fields

Submitting form with enter key in Angular unit test

会有一股神秘感。 提交于 2019-12-08 16:58:52
问题 I'm writing a test for an Angular 4 component that is a login form. The form can be submitted by clicking on the "submit" button or by hitting enter in any input fields. This behaviour is dictated by the Angular form directive. I can write a test case that validates that a button click submits the form, but I can't trigger the submit behaviour with a keypress event. Template: <form (ngSubmit)="onLoginSubmit()" #loginForm="ngForm"> <div class="form-group"> <label for="userid">User ID</label>

How to update controls of FormArray

北城余情 提交于 2019-12-08 14:46:12
问题 My form group code is as this.myForm = this._fb.group({ branch_name: ['', [Validators.required]], branch_timing: this._fb.array([ this.initBranchTiming(), ]) }); initBranchTiming() { return this._fb.group({ day: ['', []], open_from: ['00:00:00', []], open_till: ['00:00:00', []] }); } branch_name is updated by this code (<FormControl>this.myForm.controls['branch_name']).updateValue(this.branch_detail.branch_name); Now i have to update the 'day' field of form array. what to do to update the