Roshini Dissanayake
Roshini Dissanayake

Reputation: 29

How to Bind two textboxes into 1 variable in angular

I have a angular app, In this app i have a form. I have a button click action for form submittion called onActivitySubmit().

In the form i want to get something called "Distance" for that i have to textboxes. two boxes are for the distance number and another one to fill KM or Meters.

So after submiting the form i want to pass this as an one value to the database. How do i do that? For an example i if i have 2 in one textbox and KM in another box i want to pass this as an one value to the database(mongo) as 2KM.

this is my button click event.

onActivitySubmit() {

this.processing = true;
const activity = {
  distance: this.form.get('distance').value,
  type: this.form.get('type').value,
  postedBy: this.username,
}
this.activityService.newActivity(activity).subscribe(data => {
  if(!data.success) {

  } else {

  }
})

}

Upvotes: 1

Views: 50

Answers (1)

Ramesh Rajendran
Ramesh Rajendran

Reputation: 38713

try this way

const activity = {
  distance: this.form.get('distance').value.toString() + this.form.get('type').value ,
  type: this.form.get('type').value,
  postedBy: this.username,
}

Upvotes: 1

Related Questions