angular-forms

Dividing a form into multiple components with validation

浪尽此生 提交于 2019-12-31 08:33:10
问题 I want to create a single big form with angular 2. But I want to create this form with multiple components as the following example shows. App component <form novalidate #form1="ngForm" [formGroup]="myForm"> <div> <address></address> </div> <div> <input type="text" ngModel required/> </div> <input type="submit" [disabled]="!form1.form.valid" > </form> Address component <div> <input type="text" ngModel required/> </div> When I use the code above it was visible in the browser as i needed but

fetch all values in form using ngModel directive in angular

我们两清 提交于 2019-12-31 07:14:22
问题 I am trying to fetch all the values which are in form using ngModel but some how I am getting only first text boxes values. Not getting textbox values added on click of button. Example: stackblitz html: <form #profileSetUpForm="ngForm" (ngSubmit)="saveData(profileSetUpForm)" class="form "> <div class="row m-0"> <div class="col-lg-12 col-md-12 col-sm-12 col-12 profile-input-label"> Tab Name </div> <div class="col-lg-4 col-md-12 col-sm-12 col-12 mt-top-5"> <input type="text" [(ngModel)]=

Error when using setControl or patchValue in angular form array

走远了吗. 提交于 2019-12-31 04:13:27
问题 Please assist, I have nested form array, se below : this.form = this.formBuilder.group({ projectTitle: ['', [Validators.required, Validators.maxLength(300)]], projectDescription: ['', [Validators.required, Validators.maxLength(300)]], funding: this.formBuilder.array([this._buildFundingItems()]), }); the this._buildFundingItems() is as follows private _buildFundingItems(): FormGroup { return this.formBuilder.group({ items: ['', [Validators.required, Validators.pattern(this.regexValidation

Checking Multiple Row Custom Validator in Angular 4 Reactive Forms

[亡魂溺海] 提交于 2019-12-30 14:48:30
问题 I have a very simple problem which I can't get it. First, I have an ingredient which has an approved quantity. And that ingredient has several expiration dates. However, I want to check if my expiration dates which has the "quantity to transfer" is not more than the approved quantity. How should I check this? I already finished some parts BUT this one I couldn't compare since it has to check several rows of "quantity to transfer" against the one approved quantity. Here's the code link below:

No provider for ControlContainer - Angular 5

自古美人都是妖i 提交于 2019-12-30 07:55:13
问题 I am converting a purchased, third-party template into an Angular 5 app, and just ran into an error. I am very new to Angular 5 (I know AngularJS well however) and don't understand what it's trying to tell me? It seems to be related to a button which shows/hides the top navbar. Error Message (from browser): Error: Template parse errors: No provider for ControlContainer ("imalize-styl-2 btn btn-primary " (click)="toggleNavigation()"><i class="fa fa-bars"></i> </a> [ERROR ->]<form role="search"

Assigning a file to a Variable using angular forms and ngModel

倖福魔咒の 提交于 2019-12-25 01:37:34
问题 I want to use a form to assign a file to a variable so that I can then post the file to my back end server. My form looks like the following: <form (ngSubmit)='onSubmit()' #myform='ngform'> <div class="fileup"> <label for='file'> Upload </label> <input id='file' type='file' name='file' [(ngModel)] = 'uploadedFile' /> <button type='submit' class='btn btn-basic'> Upload </button> </form> {{ uploadedFile ¦ json }} The final line is just for development purposes and allows me to see the value of

How to get checked values into an array for Angular Template Driven Form (ngModel)

天涯浪子 提交于 2019-12-24 21:15:53
问题 I'm attempting to use template driven forms, binding to a model in the html to a new instance of lets say Person . I've been unsuccessful in creating a proper binding for checkboxes to a single array property on my model. The idea is data will come from an api or other source, dynamically render checkboxes via *ngFor and bind what is selected to the Person models property which would be an array of numbers. For example: class Person { firstName: string; someCheckboxPropList: number[]; } and

How to set Checkbox FormControl for Multiple array control

邮差的信 提交于 2019-12-24 17:50:01
问题 I am trying toggle/check according specific permissions with array set id's - to set permissions for users according to their user role. for an example an admin would have permissions to create users, delete, and update. My struggle with the code i've posted below is that it toggles all permissions instead of ones passed into formControl im not sure if im doing right. public userList: Array < User > ; public principalList: Array < Principal > ; public permissionList: Array < PermissionItem >

Angular Reactive Form submit and clear validation

只愿长相守 提交于 2019-12-24 14:05:39
问题 I have a reactive form <form [formGroup]="secondFormGroup"> <ng-template matStepLabel>enter items</ng-template> <div style="display: flex; flex-direction: column;"> <mat-form-field> <input matInput type="text" placeholder="category" [(ngModel)]="newItem.CategoryName" formControlName="category" /> </mat-form-field> <mat-form-field> <input matInput type="text" placeholder="sub category" [(ngModel)]="newItem.SubCategoryName" formControlName="subCategory" /> </mat-form-field> <mat-form-field>

Angular ReactiveForm Error Handling Through Switch Case

五迷三道 提交于 2019-12-24 10:51:11
问题 I have a reactive form in which I validate the different fields with ngif. For example: <mat-form-field> <input matInput formControlName="name" placeholder="Name"> <mat-error *ngIf="personForm.get('name').hasError('required')">Name is empty</materror> <mat-error *ngIf="personForm.get('name').hasError('minlength')">Needs more than 3 characters</mat-error> </mat-form-field> Would it be possible to do the same thing in a switch case statement and how would one go on about doing this? I imagened