1

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 {

  }
})

}

1
  • do you know anything about concatenation? Commented Jul 27, 2017 at 7:00

1 Answer 1

1

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,
}
Sign up to request clarification or add additional context in comments.

10 Comments

Then he want remove the space. it's just a common sense. :) any way I have update my answer
But what I don't understand is why you are putting ''?Won't this work distance: this.form.get('distance').value.toString() +this.form.get('type').value ?
Because if the distance value is integer. it may be threw conversion error. that's why I have convert to string then concatenate. previously am not using toString(). that's why am using ''. but any way we won't it. i'll update it. thanks for your attention
The please give me the mark as answer @RoshiniDissanayake
How do i do that? Where ?
|

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.