angular4-forms

What is the ideal way to sort a FormArray object in Angular 2+?

点点圈 提交于 2021-02-18 21:00:47
问题 I have a formArray which consist of multiple form groups. I need to sort the array dynamically based on a boolean field present in each of the form group in the array. The boolean field is a checkbox and at any given point of time only one checkbox can be checked (mimics radio button). So when a checkbox is clicked I need to sort the formArray based on the one that is selected. I know the documentation suggests not to mess with the AbstractControls[] present in the formArray, so what would be

Submitting a form by pressing enter key in angular 4

 ̄綄美尐妖づ 提交于 2021-02-08 10:42:20
问题 By pressing Enter key need to submit the form in angular 4 below is my code in form Action = "" is not working. I also tried with (keydown) = domonething(event) and (keydown.enter) = domonething(event) with below code keyDownFunction(event) { if (event.keyCode == 13) { this.submit(); } } Below is my current code <form #f="ngForm" (ngSubmit)="f.form.valid && openModal(confirmationmodal)" novalidate action=""> <div class="form-group form-row"> <label class="col-form-label col-sm-4 col-md-4" for

Submitting a form by pressing enter key in angular 4

坚强是说给别人听的谎言 提交于 2021-02-08 10:41:26
问题 By pressing Enter key need to submit the form in angular 4 below is my code in form Action = "" is not working. I also tried with (keydown) = domonething(event) and (keydown.enter) = domonething(event) with below code keyDownFunction(event) { if (event.keyCode == 13) { this.submit(); } } Below is my current code <form #f="ngForm" (ngSubmit)="f.form.valid && openModal(confirmationmodal)" novalidate action=""> <div class="form-group form-row"> <label class="col-form-label col-sm-4 col-md-4" for

Submitting a form by pressing enter key in angular 4

强颜欢笑 提交于 2021-02-08 10:41:19
问题 By pressing Enter key need to submit the form in angular 4 below is my code in form Action = "" is not working. I also tried with (keydown) = domonething(event) and (keydown.enter) = domonething(event) with below code keyDownFunction(event) { if (event.keyCode == 13) { this.submit(); } } Below is my current code <form #f="ngForm" (ngSubmit)="f.form.valid && openModal(confirmationmodal)" novalidate action=""> <div class="form-group form-row"> <label class="col-form-label col-sm-4 col-md-4" for

Dynamically Add Rows Based on Condition Using Reactive Forms in Angular

拟墨画扇 提交于 2021-01-28 08:00:51
问题 Is it possible that i will be able to add rows based on certain condition in Angular reactive forms? If yes, please help me do it. I've already started it in my stackblitz. Please check this link https://stackblitz.com/edit/dynamically-add-rows this.addForm.get("items").valueChanges.subscribe(val => { console.log(val); if (val === true) { this.addForm.get("items_value").setValue("yes"); // How to add row here? this.addForm.addControl(rows, 'rows') } if (val === false) { this.addForm.get(

Angular error: The left-hand side of an assignment expression must be a variable or a property access

一笑奈何 提交于 2020-12-12 03:27:12
问题 Do not understand or know how to fix this error. This is the code. It seems to be something to do with pushItem function i think. > **app.component.ts** import { Component, NgModule } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { //bind this array to li in html items = ['Sistema', 'Playstation', 'Web']; newItem = ''; pushItem = function() { if(this.newItem ! = ''){ this.items.push

Angular error: The left-hand side of an assignment expression must be a variable or a property access

前提是你 提交于 2020-12-12 03:23:58
问题 Do not understand or know how to fix this error. This is the code. It seems to be something to do with pushItem function i think. > **app.component.ts** import { Component, NgModule } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { //bind this array to li in html items = ['Sistema', 'Playstation', 'Web']; newItem = ''; pushItem = function() { if(this.newItem ! = ''){ this.items.push

angular 4- How do I send file in POST to backend

感情迁移 提交于 2020-08-27 22:26:35
问题 I have a file upload in the form. I need to create post request to backend with this uploaded file and some other form fields too. Below is my code: fileChange(event) { const fileList: FileList = event.target.files; if (fileList.length > 0) { this.file = fileList[0]; this.form.get('file_upload').setValue(this.file); } } onClick(){ const val = this.form.value; const testData = { 'file_upload': this.file, 'id': val.id, 'name' : val.name, 'code': val.code, }; this.http.post('https://url',