angular2-forms

How to change validation of a control after it has been initiated?

我与影子孤独终老i 提交于 2019-12-12 01:29:29
问题 I am wondering how can I dynamically change Validation on a field. I have control group, which has 5 fields. For this, I want to use custom validator on this control group, to check if any of the inputs are not empty. If any of those are empty, I want to set validation of all of the fields within this control group to be required. To do this, I need to dynamically change validation of each control to be required, after I verify if any of the inputs are empty. I got the first part - but I

Using setControl in nested reactive form

陌路散爱 提交于 2019-12-11 19:56:38
问题 I would like to know what I have to do to use the "setControl" and "get" in a reactive form when I have an array inside of another formBuilder group. For instance: this.formulario = this.formBuilder.group({ title: [this.racPessoa.title, [Validators.required]], description: [this.racPessoa.description, [Validators.required]], person: this.formBuilder.group({ idPerson:[this.racPessoa.person.idPerson], name:[this.racPessoa.person.nome], personDocument: this.formBuilder.array([]) }), }); In the

How I get & validate the username and password in SQL Management using API?

*爱你&永不变心* 提交于 2019-12-11 17:32:49
问题 I created my login page and i want to validate the username and password. Then i need to get the user details using API from the database. please send me a coding using ionic-3 and angular-2. I already tried in my SQL. But i want it in SQL management. In the below coding i send the parameters using post method and it will get at back end and validate with already registered username and password. Username: any; Password: any; data:string; constructor( ){} //declaration of object// var headers

How to set maximum limit of checked elements in MD-selection-list Angular2

删除回忆录丶 提交于 2019-12-11 09:23:50
问题 i have md-selection-list with *ngFor of some tags, for example [sport,relax,..] The tags are stored in this.tags , and the selected tags are stored in this.tab I want to prevent user for selecting more than 5 tags. So if user select 5th item, there should be some alert, and user can type different tag only when unchecked some of checked items. I start with this code, but it isn't working. I try to disable this "check" icon on list-item, and then not add the item to this.tab until the user

Angular 2 - Creating form in a subscription causes crash saying the formGroup is undefined

心已入冬 提交于 2019-12-11 09:23:29
问题 I've got some data in my Firebase database, this data I want to apply to a form via FormBuilder . It works somewhat good but I get errors more often than not saying formGroup expects a FormGroup instance. Please pass one in. . What doesn't make sense is that when I apply new changes to the database which cause the subscription to fire, I get the error. Despite this.settingsForm being set before and after the subscription runs after updating. Here's the subscription: this.eventSubscription =

Reset ngModel values on ngIf in angular2

*爱你&永不变心* 提交于 2019-12-11 08:08:06
问题 I have a model which is an array element. I want to clear the values of each element on ngIf condition.Please find below HTML : <div *ngIf="flag" > <table id="table" class="table table-hover table-bordered table-mc-light-blue"> <thead> <tr> <th>col 1</th> <th>col 2</th> </tr> </thead> <tr *ngFor="let item of collection;"> <td>{{item.col1}}</td> <td> <input type="text" class="form-control" [(ngModel)]="item.col2" #input="ngModel" name="input-{{i}}"> </td> </tr> </table> </div> On flag set to

Angular 2 forms; ngFormControl for radio and select

家住魔仙堡 提交于 2019-12-11 07:35:47
问题 I am making an app in Angular and am currently working on a forms section. With the help of a custom ngFormModel I have can generate per defined forms with validation simply with the following: <form [ngFormModel]="customForm" (ngSubmit)="updateUser()"> <input [ngFormControl]="customForm.controls['name']" type="text"> <input [ngFormControl]="customForm.controls['email']" type="text> <button *ngIf="customForm.dirty" type="submit">Save</button> </form> This works quite awesome, default values

Exporting firebase data and set it as default input in template driven form

让人想犯罪 __ 提交于 2019-12-11 07:28:33
问题 I am creating an app using angular 4.0.2, angularfire2, and firebase, off course. What the problem is I am not able to use the data from angularfire2 and set it as default input value of an input used in model-driven or reactive form. Here is my code for add-invoice.component.ts ngOnInit(){ const datafetch = firebase.database().ref().child('/invoices').orderByKey().limitToLast(1).once('value').then(snapshot => { const names = []; snapshot.forEach(function(childSnapshot) { var childKey =

Display value inside input

烂漫一生 提交于 2019-12-11 07:27:32
问题 I have designed my form till here. Now I further want to show the amount of the particular row over there in the row in Amounts column. <input type="text" class="form-control" formControlName="itemamt" readonly value="{{itemrow.get('itemqty').value * itemrow.get('itemrate').value}}"> 回答1: To pass FormControll Value inside FormArray you can do something like this with angular, form = new FormGroup({ name: new FormControl('Name'), username: new FormArray([ new FormControl("value"), {firstName:

Angular2: email already exist as custom Validator?

∥☆過路亽.° 提交于 2019-12-11 06:55:39
问题 I created a form with Angular2 and I created the following method to check if the email address already exist. Here is my code: checkEmail(): void { // FIRST PART this.found = false; // If user is not Premium... if (!this.currentUser.isPremium) { // ...and if user typed something in the input field, then apply validitor for email address if (this.myForm.controls.email.value.length > 0) { this.myForm.controls.email.setValidators([validateEmail()]); this.myForm.controls.email