angular2-forms

Angular 2 custom form Validation does not prevent onSubmit from being called

浪子不回头ぞ 提交于 2019-12-23 10:57:24
问题 Perhaps I am being dumb but I cannot for the life of me figure out how to get custom form validation to stop onSubmit from being called when the validation fails. I've tried using both the HTML syntax (by adding the custom validation keyword directly into the htmlTemplate of the form component) as well as through the code, when creating a new Control. I also haven't seen anything that suggests this feature shouldn't work for custom validators. Here's an example of the code I'm using import {

How can I add a formGroup to another formGroup

百般思念 提交于 2019-12-23 10:46:09
问题 I found this answer which shows how I can add form controls to the parent form: Reuse components in angular2 model driven forms but I would like to be able to add new formGroups to different areas of the page like this. <form [formGroup]="myForm"> <!--... other inputs --> <md-tab-group formGroupName="nutrition"> <md-tab formGroupName="calories"> <template md-stretch-tabs="always" md-tab-label>Calories</template> <template md-tab-content> <calories></calories> <!-- I want to add controll

Set reactive form after data loaded (async) - Angular 5

℡╲_俬逩灬. 提交于 2019-12-23 08:01:57
问题 I am trying to update the form values after loading values from an API. I tried using the *ngIf technique but the form is not visible even when the form is set. I am not able to share the full project, but here is the component template and controller Template <div class="page-title"> <h3> Edit news </h3> </div> <div class="partner-add-form"> <ng-container *ngIf='newsForm'> <form action="" [formGroup]='newsForm' (ngSubmit)="onSubmit()"> <div class="row "> <div class="input-field col s12

@angular/forms Generic type 'Type<T>' requires 1 type argument(s)

我只是一个虾纸丫 提交于 2019-12-23 07:56:10
问题 I upgraded Node and NPM and reinstalled Angular CLI( angular-cli: 1.0.0-beta.11-webpack.8, node: 6.5.0, os: linux x64 ), generated a foo project which worked fine. Then I bumped Angular 2 to RC.6 and got this error: jan@linux-zd16:~/src/fm-repos/foo> ng serve ERROR in [default] /home/jan/src/fm-repos/foo/node_modules/@angular/forms/src/directives.d.ts:26:45 Generic type 'Type<T>' requires 1 type argument(s). ERROR in [default] /home/jan/src/fm-repos/foo/node_modules/@angular/forms/src

Angular 2.0 and TypeScript - Populate <select> options from multi-dimensional array objects

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 23:07:27
问题 I would like to populate the <select name="selectmodel"> <option> from a nested array of objects based on the selection of the <select name="selectmake"> <option> element. Here is the multi-dimensional array: muscleCars = [ { id: 1, name: "Chevrolet", models: [ { model: "Camaro" }, { model: "Corvette" } ] }, { id: 2, name: "Dodge", models: [ { model: "Charger" }, { model: "Challenger" }, { model: "Viper" } ] }, { id: 3, name: "Ford", models: [ { model: "GT" }, { model: "Mustang" } ] } ]; This

Repeat password validation not working

泄露秘密 提交于 2019-12-22 17:21:10
问题 I am trying to validate password and repeat password in a form. Like this import { FormGroup, FormBuilder, Validators, AbstractControl } from '@angular/forms'; this.registerForm = fb.group({ name: ['', Validators.required], email: ['', Validators.compose([Validators.pattern("[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"), Validators.required])], passwords: this.fb.group({ password: ['', Validators.compose([Validators.required])], repassword: ['', Validators.compose([Validators.required])

Angular2 - read binary file from input file and bind it to object

与世无争的帅哥 提交于 2019-12-22 12:07:25
问题 I have get the file binary content of multiple file upload inputs that are binded to an array of structured object. The scenario is this: I have a class like this: export class PriceList { public idPriceList: number; public code: string; public name: string; public binary: any;//this property has to contain the binary content of the selected file } Then I have my array that is filled by webapi and is used to compose the form: public listFile: PriceList[] = []; Now in component I have

Angular2 ReactiveFormsControl: how to bind radio buttons?

牧云@^-^@ 提交于 2019-12-22 11:27:33
问题 I'm using ReactiveFormsModule of Angular2 to create a component that contains a form. Here is my code: foo.component.ts constructor(fb: FormBuilder) { this.myForm = fb.group({ 'name': ['', Validators.required], 'surname': ['', Validators.required], 'gender': [] }); } foo.component.html <div class="two fields"> <div class="four wide field"> <label>Name*</label> <input type="text" [formControl]="myForm.controls.name"/> </div> <div class="four wide field"> <label>Surname*</label> <input type=

JavaScript heap out of memory in angular 2

浪子不回头ぞ 提交于 2019-12-22 11:16:05
问题 I am using Angular CLI. Please check my CLI info @angular/cli: 1.2.1 node: 6.10.0 os: win32 x64 @angular/animations: 4.1.1 @angular/common: 4.0.0 @angular/compiler: 4.0.0 @angular/compiler-cli: 4.0.0 @angular/core: 4.0.0 @angular/forms: 4.0.0 @angular/http: 4.0.0 @angular/platform-browser: 4.0.0 @angular/platform-browser-dynamic: 4.0.0 @angular/router: 4.1.1 When I use ng serve --aot I am getting the following error. Last few GCs 893427 ms: Mark-sweep 1344.1 (1434.3) -> 1339.9 (1434.3) MB,

patch Value in a nested form control using angular2

匆匆过客 提交于 2019-12-22 09:03:25
问题 I need to set a value in a nested control in a FormBuiler and the model is the following: this.addAccForm = this.fb.group({ accid: ['', Validators.required], status: '', cyc: this.fb.array([ this.initCyc(), ]) }) initCyc() { return this.fb.group({ cycid: ['', Validators.required], name: ['', Validators.required], description: ['', Validators.required], status: ['', Validators.required], det: this.fb.group({ dcycid: ['', Validators.required], status: ['', Validators.required] }) }) I need to