angular2-forms

FormArray usage and dynamically add row of controls

冷暖自知 提交于 2019-12-11 06:53:45
问题 I'm having trouble trying to do something with Angular 2 and Forms. I have let's say an invitation list, where there are two fields, for name and e-mail, and a button to add more rows. |__name_______|__e-mail_______| |__name_______|__e-mail_______| (+) Add row And I kinda know that you can use FormArray to dynamically store different rows and so, but I'm not sure how to use it and to make it work. So far at my component I have form:FormGroup; ngOnInit() { this.form = new FormGroup({ invitee:

angular2 async validation this.subscribe exception?

不问归期 提交于 2019-12-11 05:46:21
问题 I try to implement async(isUnique) and sync(cannotContainSpace) validation functions for username field, I want to see "this username already in use alert msg, if textbox value is "yener". sync function works fine but i think ss below can help explain my issue; Note:canNotContain sync validation func works fine, aafter I added isUnique async function this exception occured.. how can I fix it ? usernamevalidator.ts import {FormControl} from '@angular/forms'; export class UsernameValidator{

How to write custom form validator (model-driven) that depends on current component's property value in Angular2

十年热恋 提交于 2019-12-11 05:16:23
问题 I am working with the latest angular2 forms and struggling with this seems-to-be-simple task. I want to have a custom validation function that is able to read the current component's property and validate the input based on that. Here is the example plnkr: http://plnkr.co/edit/bNFjNsCfhYjoqKaRZgQU?p=preview In this example, I have a username field which is always required, and a password field that will only be needed if the customer is an existing one. My form declaration is: this.loginForm

How to get selected option from select and assign it to select ngModel

梦想与她 提交于 2019-12-11 04:38:35
问题 I have the following select menu: <div class="medium-3 columns"> <label>First Menu <select name="first-menu"> <option *ngFor="let i of items" [value]="i.name">{{i.name}}</option> </select> </label> </div> I would assing a model to the select menu so i edited the code in the following way (i see it here): <div class="medium-3 columns"> <label>First menu <select [ngModel]="myForm.firstMenu" (ngModelChange)="onSelected($event)" name="first-menu"> <option *ngFor="let i of items" [value]="i.name">

Angular2 create model nested forms

北城以北 提交于 2019-12-11 04:27:09
问题 i am trying to create nested forms but i am stuck in the second level and not sure how the addAttribute and removeAttribute will look like ? export class ExportFormComponent implements OnInit { public exportForm: FormGroup; constructor( private formBuilder: FormBuilder ) { } ngOnInit() { this.exportForm = this.formBuilder.group( { dataType: [''], items: this.formBuilder.array( [ this.initItem(), ] ) }); } initItem() { return this.formBuilder.group( { exportExpression: [''], description: [''],

NativeScript ng2 two way binding doesn`t work on TextField

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 04:25:55
问题 im making a mobile app. In my login form i have 2 TextFields <TextField hint="Email Address" keyboardType="email" [(ngModel)]="email" autocorrect="false" autocapitalizationType="none"></TextField> <TextField hint="Password" secure="true" [(ngModel)]="password"></TextField> <Label [text]="email"></Label> in component.ts import { Component, OnInit } from '@angular/core'; import { Router } from "@angular/router"; import { NativeScriptRouterModule } from "nativescript-angular/router"; import {

Angular 2: How to link form elements across a dynamically created components?

懵懂的女人 提交于 2019-12-11 02:13:25
问题 I have a set of form fields that are in a dynamically created component. The parent Component owns the form tag. However, none of the form fields are being added to the Form . I'm using the ComponentFactoryResolver to create the component: @Component({ selector: 'fieldset-container', templateUrl: './fieldset-container.component.html', styleUrls: ['./fieldset-container.component.scss'], entryComponents: ALL_FIELD_SETS, }) export class FieldsetContainerComponent<C> { fieldsetComponent :

Angular 2 Form Async validation ajax call on every keypress

回眸只為那壹抹淺笑 提交于 2019-12-11 01:58:11
问题 I am playing with angular 2 forms async validation, everything is working fine but then i realised ajax call is made to server on every key press inside input field which is not good for server, i tried many things but nothing works. So please help me to how to deal with this problem. form: FormGroup; username: FormControl; password: FormControl; constructor(private fb: FormBuilder, private http: Http) { this.username = new FormControl("", Validators.compose([ Validators.required,

Angular2: Disable a formbuilder's element

爷,独闯天下 提交于 2019-12-11 01:08:31
问题 I'm trying to disable an element of my formbuilder after the declaration because I have to validate something once my view is loaded, so this is my formBuilder declaration. ionViewDidLoad() { this.purchaseDataForm = this.formBuilder.group({ kms: ['', Validators.required], lts: ['', Validators.required], price: ['', Validators.required], total: ['', Validators.required] }); } I have no idea how to do that because I want to disable the total element once finished my local validation. I hope you

How to assign selected value to “Select” when value is of class object in angular 2

ⅰ亾dé卋堺 提交于 2019-12-10 23:32:12
问题 Using angular 2.2.4 from following links learned select list of class object: How can I get new selection in "select" in Angular 2? https://stackoverflow.com/a/35945293/4773561 Angular 2 Dropdown Options Default Value & implemented as follows <select id="st" name="state" [(ngModel)]="selectedState" (ngModelChange)="onStateSelectedForVanue($event)"> <option *ngFor="let state of states" [ngValue]="state">{{state.name}} </option> </select> here 'states' is list of State Class object export class