I am facing an issue with my form in Angular 2. When the user clicks on the submit button, I intend to send the data to a rest endpoint using the http module. Here is the structure of the form:
<form novalidate [formGroup]="formGroup()" (ngSubmit)="send()">
<input (change)="enableThree($event.target.checked)"
formControlName="one" type="checkbox" />
<input (change)="disable($event.target.checked)"
formControlName="two" type="checkbox" >
<input formControlName="three"type="text" >
<input formControlName="four" type="text" >
<input formControlName="five" type="text" >
<input formControlName="six" type="number" >
<button>Go</button>
</form>
Here is the component responsible for the functionalities:
import { Component, OnInit} from '@angular/core';
import { FormBuilder, FormGroup, FormControl} from '@angular/forms';
import { MyService } from '../my.service';
@Component({
selector: 'my-form',
templateUrl: './form.component.html',
styleUrls: ['./form.component.scss']
})
export class FormComponent implements OnInit {
private readonly fb: FormBuilder;
private readonly myForm: FormGroup;
private data: any;
private myService : MyService;
constructor(formB: FormBuilder, myService : MyService) {
this.myService = myService;
this.fb = formB;
this.myForm = this.fb.group({
thre: [{
value: "",
disabled: true
}],
four: new FormControl(""),
five: new FormControl(""),
six: new FormControl(""),
one:new FormControl(""),
two:new FormControl("")
});
}
// Methods to handle form functionalities
}
And the service class for handling HTTP requests:
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions} from '@angular/http';
import { Entity } from './entity';
@Injectable()
export class MyService {
// HTTP request methods
}
However, I am facing an issue where the update functionality triggers an unexpected HTTP post request in addition to the put request. This issue does not occur when adding or deleting entities. Also, the console.log message in the send() function is only printed once.
If you have any tips or suggestions on how to resolve this issue, I would greatly appreciate it. Thank you!