0

I am new so don't mistake me if i asked small questions or wrong questions

<form >
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname"><br><br>
</form>
<button>submit<button>

I want to send this all value to api through angular

1 Answer 1

1

If you're using angular you should know about : https://material.angular.io/guides

your angular html

<form [formgroup] = formname>
  <label for="fname">First name:</label>
  <input formControlname=name type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last name:</label>
  <input formControlname=name type="text" id="lname" name="lname"><br><br>
</form>
<button (click)="submitdata()">submit<button>

your TS file

import{HttpClient}............
import{FormBuilder, FormGroup, Validators, FormControl}........
const(private formbuilder:FormBuilder, private http:HttpClient)
formname!:formgroup;
ngOnInit{
this.formname = this.formbuilder.group({
name : ['',validators.required];
lname : ['', validators.required];
})
}
submitdata(){
this.http.post('your_url', this.formname.value)
}


Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.