angular4-forms

Angular dynamic form nested fields

房东的猫 提交于 2019-12-02 20:00:41
问题 With the help of https://angular.io/guide/dynamic-form, i am making a dynamic form where i am in the need to display two fields at first. new TextboxQuestion({ key: 'firstName', label: 'First name', value: '', required: true, order: 1 }), new TextboxQuestion({ key: 'lastName', label: 'Last name', value: '', required: true, order: 2 }), These two fields needs to be at first on loading. After this i will have two buttons as add and remove . <button (click)="addNew()"> Add </button>     <button

Angular dynamic form nested fields

北城余情 提交于 2019-12-02 12:01:55
With the help of https://angular.io/guide/dynamic-form , i am making a dynamic form where i am in the need to display two fields at first. new TextboxQuestion({ key: 'firstName', label: 'First name', value: '', required: true, order: 1 }), new TextboxQuestion({ key: 'lastName', label: 'Last name', value: '', required: true, order: 2 }), These two fields needs to be at first on loading. After this i will have two buttons as add and remove . <button (click)="addNew()"> Add </button>     <button (click)="removeNew()"> Remove </button> <br><br> By clicking add, i need to display the next two

How to set first option as selected where options build from loop in select box anular 4

自作多情 提交于 2019-12-02 11:34:48
I have worked on angular 4 project, In this project, I have a requirement to set the first option as selected where all options are created dynamically by loop. html code: <select [(ngModel)]="selectedServiceType" [ngModelOptions]="{standalone: true}" (ngModelChange)="getServiceType($event)"> <ng-container *ngFor="let service of services"> <option [ngValue]="service">{{service.name}}</option> </ng-container> </select> If anyone know about let me know. Thanks in advance! Try like this : <select class="form-control" (change)="onChange($event)"> <option *ngFor="let service of services; let

Angular 4 Form Validators - minLength & maxLength does not work on field type number

懵懂的女人 提交于 2019-11-30 16:54:35
I am trying to develop a contact form, I want user to enter phone number values between length 10-12. Notably same validation is working on Message field, Its only number field which is giving me trouble. I found this answer but it is of no use for me. I have code like following : HTML : <form [formGroup]="myForm" (ngSubmit)="myFormSubmit()"> <input type="number" formControlName="phone" placeholder="Phone Number"> <input type="text" formControlName="message" placeholder="Message"> <button class="button" type="submit" [disabled]="!myForm.valid">Submit</button> </form> TS : this.myForm = this

Property 'controls' does not exist on type 'AbstractControl' Angular 4

岁酱吖の 提交于 2019-11-30 03:02:27
I am trying a nested reactive form in Angular 4. It is working fine but when I try to build AOT it's throwing the error 'controls' does not exist on type 'AbstractControl' I googled and tried few things but no luck. Could anyone tell me how to fix this issue? <div [formGroup]="myForm"> <div formArrayName="addresses"> <div *ngFor="let address of myForm.get('addresses').controls; let i=index" class="panel panel-default"> <span *ngIf="myForm.get('addresses').length > 1" (click)="removeAddress(i)">Remove</span> <div [formGroupName]="i"> <mat-form-field> <input matInput formControlName="city"

Angular 4 Form Validators - minLength & maxLength does not work on field type number

霸气de小男生 提交于 2019-11-30 00:13:50
问题 I am trying to develop a contact form, I want user to enter phone number values between length 10-12. Notably same validation is working on Message field, Its only number field which is giving me trouble. I found this answer but it is of no use for me. I have code like following : HTML : <form [formGroup]="myForm" (ngSubmit)="myFormSubmit()"> <input type="number" formControlName="phone" placeholder="Phone Number"> <input type="text" formControlName="message" placeholder="Message"> <button

Get Value From Select Option in Angular 4

一世执手 提交于 2019-11-29 01:13:09
How do I get the value from the select option in Angular 4? I want to assign it to a new variable in the component.ts file. I've tried this but outputs nothing. Can you also do it using [(ngModel)]? component.html <form class="form-inline" (ngSubmit)="HelloCorp(f)" #f="ngForm"> <div class="select"> <select class="form-control col-lg-8" #corporation required> <option *ngFor="let corporation of corporations" [value]="corporationObj">{{corporation.corp_name}}</option> </select> <button type="submit" class="btn btn-primary manage">Submit</button> </div> </form> component.ts HelloCorp() { const

Property 'controls' does not exist on type 'AbstractControl' Angular 4

女生的网名这么多〃 提交于 2019-11-27 03:59:50
问题 I am trying a nested reactive form in Angular 4. It is working fine but when I try to build AOT it's throwing the error 'controls' does not exist on type 'AbstractControl' I googled and tried few things but no luck. Could anyone tell me how to fix this issue? <div [formGroup]="myForm"> <div formArrayName="addresses"> <div *ngFor="let address of myForm.get('addresses').controls; let i=index" class="panel panel-default"> <span *ngIf="myForm.get('addresses').length > 1" (click)="removeAddress(i)

Angular4 - No value accessor for form control

早过忘川 提交于 2019-11-26 21:47:52
I have a custom element : <div formControlName="surveyType"> <div *ngFor="let type of surveyTypes" (click)="onSelectType(type)" [class.selected]="type === selectedType"> <md-icon>{{ type.icon }}</md-icon> <span>{{ type.description }}</span> </div> </div> When I try to add the formControlName, I get an error message: ERROR Error: No value accessor for form control with name: 'surveyType' I tried to add ngDefaultControl without success. It seems it's because there is no input/select... and I dont know what to do. I would like to bind my click to this formControl in order that when someone clicks

Get Value From Select Option in Angular 4

落花浮王杯 提交于 2019-11-26 17:46:02
问题 How do I get the value from the select option in Angular 4? I want to assign it to a new variable in the component.ts file. I've tried this but outputs nothing. Can you also do it using [(ngModel)]? component.html <form class="form-inline" (ngSubmit)="HelloCorp(f)" #f="ngForm"> <div class="select"> <select class="form-control col-lg-8" #corporation required> <option *ngFor="let corporation of corporations" [value]="corporationObj">{{corporation.corp_name}}</option> </select> <button type=