angular4-forms

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

戏子无情 提交于 2020-08-27 22:25:38
问题 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',

How to change the output date format of input type=“date” in angular 4?

不羁岁月 提交于 2020-04-10 13:59:28
问题 Actually I am working with angular 4 application. I am having a scenario like, I have to send the Date for as dd/mm/yyyy to the server. I am using property as input type ="date". But this property returns the value like yyyy/mm/dd . so how do I change the output format of the Date. Students.html <input type="date" [(ngModel)]="Students.dob" name="Students.dob"> After selecting the date, when I am check with console.log(). Students.components.ts checkDate() { console.log(Students.dob); }

Handling multiple radio buttons in a Quiz Angular 5

自作多情 提交于 2020-03-24 00:34:25
问题 I'm new to Angular and Implementing a Quiz containing multiple MCQs. But I am having trouble in radio button selection. My Questions are coming from the database and Options too. mcq.component.html <form (ngSubmit)="ff.form.valid && answer(ff)" #ff="ngForm"> <div *ngFor="let question of questions"> <p style="font-size: 25px;">{{question.title}}</p> <div *ngFor="let option of question.options"> <input [(ngModel)]="option_model.selected_option_id" #selected_option_id="ngModel" type="radio"

Angular 2/4 : Reactive forms are synchronous while template-driven forms are asynchronous, How?

こ雲淡風輕ζ 提交于 2020-02-28 07:42:30
问题 I was going through the doc of angular.io (Reactive forms are synchronous), trying to understand the reactive forms (how they are synchronous and template driven forms are asynchronous). But the doc doesn't have enough explanation with example . Can anyone help me understand how template driven forms are asynchronous and reactive forms are synchronous? I tried to explore a lot of blogs on the internet but didn't get an answer. Any help is appreciated. 回答1: Read this line careful in same

Angular 4 - validator custom function this is undefined

一笑奈何 提交于 2020-01-30 05:38:07
问题 I'm building an app with component FormComponent. inside I'm using reactive forms module from angular core and create a custom validator. the function is calling another function by using this - as I supposed it will refer to the FormComponent, but it refers to be 'undefined' (?) The code in onInit defines the FormGroup and FormControl and outside of it defines the functions import { Component, OnInit } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms';

how to implement confirm on exit in angular 4?

大憨熊 提交于 2020-01-07 08:23:46
问题 I want to know how can I implement a confirm-on-exit component so that on page refresh or leaving tab or window or screen I can execute a confirm on exit method, so that if user click OK he will leave the screen and on click on NO he will remain on same screen? Code I am using here is: import { Component, OnInit, Input, Output, HostListener } from '@angular/core'; @Component({ selector: 'confirmonexit', templateUrl: './confirm-on-exit.html' }) export class ConfirmOnExitComponent { @Input()

is that possible to send FormData along with Image file to web API from Angular 6 application

匆匆过客 提交于 2020-01-05 23:16:32
问题 Is it possible to pass the form data along with image file to web api from angular 6 application. app.component.ts onSelectFile(event) { if (event.target.files && event.target.files[0]) { this.imageToUpload = event.target.files[0]; const reader = new FileReader(); reader.onload = e => this.selectedImage = reader.result.toString(); this.fileName = event.target.files[0].name; reader.readAsDataURL(this.imageToUpload); } } createNewComitteeMember() { var mServiceObject = { ComitteeMemberName:

angular - Angular Material 2 Stepper Controls

大憨熊 提交于 2020-01-02 06:28:21
问题 I set up a linear stepper using the Angular Material 2 Stepper. I have forms in different components (component-a, component-b, component-c). In my main container component (container-component) I want to have linear stepper that 'steps' through each component when their form is valid. Is there some sort of functionality to talk up to the stepControl in the stepper to make it properly work? I have attached documentation for the stepper and a StackBlitz version of the application. Also, a link

Angular, How to set validation for either of two field should validate in reaction form approach

只愿长相守 提交于 2020-01-01 19:24:13
问题 I'm trying to set user form validation, user must enter either of two fields, mobile or email fields Add Guest reaction form Html: <form class="new_guest" id="new_guest" [formGroup]="addGuestForm" (ngSubmit)="onSubmit()"> <div class="form-group"> <input placeholder="Enter guest name" class="add-guests form-control ui-autocomplete-input" type="text" formControlName="name" id="guest_name" autocomplete="off"> </div> <div class="form-group"> <input placeholder="Enter guest email" class="add

Passing data from service to Component --> Child Components

你说的曾经没有我的故事 提交于 2019-12-31 03:00:52
问题 To be very short i am using this Plunker I have a scenario where i have to create controls dynamically by reading the elements data from a service. So when i read the data from the service its asynchronous.But i have to create some concrete objects based on the data i receive from the service and pass it to the child components. So here is my logic Html for the Main Component is as below. <ion-content padding class="container" *ngIf="questions"> <app-dynamic-form [questions]="questions"></app