angular2-forms

Angular2: Exception “No provider for t!” when creating a form

微笑、不失礼 提交于 2020-01-14 12:44:57
问题 <div id="my-form" class="form-inline"> <div class="form-group"> <input type="text" [(ngModel)]="name" ngControl="name" #n="ngForm" required> <div [hidden]="n.valid" class="alert alert-danger"> Value is required </div> </div> </div> I get the following (less than helpful) error with alpha.52: EXCEPTION: No provider for t! (t-> t) 回答1: Angular registers controls under their ngControl names with the NgForm. Normally, you don't have to add the NgForm directive explicitly because it automatically

Angular2 ngNoForm and also do angular form validation

◇◆丶佛笑我妖孽 提交于 2020-01-14 10:36:07
问题 I have a legacy backend server that processes form data as request parameters. We are putting angular2 on the front end. I want to submit the angular2 form so that all fields go as request parameters so that the legacy backend doesn't have to be changed. To do this I have : <form ngNoForm action="http://localhost/config/api/v1/angular/submit" target="_blank" method="POST"> But I also want to use the angular2 form validation on the submit button: <form #f="ngForm" ngNoForm action="http:/

Add checkbox dynamically using angular 2

心不动则不痛 提交于 2020-01-14 04:46:27
问题 I am new to angular and currently using angular 5 i want to add check box and drop down list on click event() using Reactive form control. Please suggest a solution. 回答1: Your html template should look something like below: <div formArrayName="items" *ngFor="let item of items.controls; let i=index"> <div [formGroupName]="i" class="well"> <input type="checkbox" formControlName="isChecked" /> </div> <div *ngIf="isChecked.invalid && (isChecked.dirty || isChecked.touched)" class="alert alert

Error: Cannot find control with path: 'x ' angular 2

∥☆過路亽.° 提交于 2020-01-13 20:38:08
问题 I am trying to make a specific form field in my overall form dynamic so that x amount of objects can be added to the array of that field. However, every time the page inits I get a Error: Cannot find control with path: 'media -> ' This is my form.ts this.cardForm = new FormGroup({ 'title': new FormControl(cardTitle), media: this._fb.array([ this.initMedia(), ]), 'links': new FormGroup({ 'news': new FormControl(news), }), initMedia() { return this._fb.group({ type: new FormControl(), raw: new

angular 2/4 multiple drop down

走远了吗. 提交于 2020-01-13 06:48:27
问题 I am trying to develop two drop downs in my Angular application. The 1st one is shop list and the other one is godown list . When I select a shop it will show it on data.but when I select Godown it's not changing data. Here I have two drop down boxes. I think my problem is in my typescript file(Onselect) because here I have 2 drop downs(in html I use 2 Onselect function but in my ts file have only one function). I'm just a beginner in Angular , so I would appreciate any comments on downsides

Angular 2+ material mat-chip-list formArray validation

[亡魂溺海] 提交于 2020-01-13 02:41:49
问题 How do I validate that a mat-chip has been added to the mat-chip-list . I am using ReactiveForms. I have tried with the required validator. The value can be a list of names, so I need to make sure that there is atleast 1 name in my list of names before I can submit the form. If the list is empty then mat-error should display the error message. Using the required validator makes the form invalid, regardless of adding names to the list. EDIT: Reactive Forms I have tried to make a custom

Angular 2+ material mat-chip-list formArray validation

霸气de小男生 提交于 2020-01-13 02:41:09
问题 How do I validate that a mat-chip has been added to the mat-chip-list . I am using ReactiveForms. I have tried with the required validator. The value can be a list of names, so I need to make sure that there is atleast 1 name in my list of names before I can submit the form. If the list is empty then mat-error should display the error message. Using the required validator makes the form invalid, regardless of adding names to the list. EDIT: Reactive Forms I have tried to make a custom

Parsers and Formatters in Angular2

…衆ロ難τιáo~ 提交于 2020-01-12 11:48:23
问题 What is the way of doing parsers and formatter in Angular2? in Angular1 it was possible to do such manipulations with ngModelController: //model -> view ngModelController.$formatters.push(function(modelValue) { return modelValue.toUpperCase(); }); //view -> model ngModelController.$parsers.push(function(viewValue) { return viewValue.toLowerCase(); }); could you provide me an example how to do it with Angular2? UPD : Pipes are similar to Filters in Angular1, but I'm looking not for Filters,

Nested Forms in angular2

二次信任 提交于 2020-01-12 09:15:13
问题 How to create form with nesting fields, i know about formArray in angular2 RC but am bit confused how to use it correctly ? let suppose i have an form like this // Main Form with formArray named as `global_modifier` this.myForm = this._fb.group({ ....... name: ['', []], global_modifier: this._fb.array([ this.initGlobalModifiers() ]) .... }); removeModifier(i: number) { const control = <FormArray>this.myForm.controls['global_modifier']; control.removeAt(i); } addModifier() { const control =

binding angular object to model-driven form in angular2

ⅰ亾dé卋堺 提交于 2020-01-11 11:33:14
问题 I have created custom controls(in component class) with binding objects to form element in html, but there is an error message shown in consele that I couldnt solve, actually message makes no sense(formGroup is special key why it tries to bind it ?) here is the image that I see in developer console in chrome: form.component.html: <div class="row"> <form class="from-horizontal" [formGroup]="form" formControlName="username" formControlName="email" (ngSubmit)="signup()"> <div class="form-group