0

As you know, if I want to the get numeric value of a variable (e.g. $event) I'd do:

   <ax-text-box (valueChange)='documentSearchItem.fromPrice=(+$event)'></ax-text-box>

I add a + to do that. Is there a simple way like this, to get the string value of a variable ? p.s. I don't want to use a method. I want to be able to use it in HTML templates.

Qiimiia
  • 510
  • 6
  • 16
  • Please describe the type or source of variable `$event`. In other words, post a [example] so we can reproduce. Numeric to String conversion is [already answered](https://stackoverflow.com/questions/5765398/whats-the-best-way-to-convert-a-number-to-a-string-in-javascript): `num.toString()` or `'' + num`. – hc_dev Aug 04 '21 at 06:11
  • 1
    Does this answer your question? [What's the best way to convert a number to a string in JavaScript?](https://stackoverflow.com/questions/5765398/whats-the-best-way-to-convert-a-number-to-a-string-in-javascript) – hc_dev Aug 04 '21 at 06:12
  • @hc_dev No it does not! I want to use it in HTML template, not in JS/TS files – Qiimiia Aug 04 '21 at 06:45
  • 1
    @Qiimiia which HTML template allows JS expressions like `+x` but not expressions like `String(x)` or `"" + x`? If `+` is *special* and only available in the templating engine you use, then you should specify *which* templating engine that is. Because the answers *have* to only target that, not a generic JS approach. – VLAZ Aug 04 '21 at 07:32

2 Answers2

1
let v = 2 // whatever value
let s = v.toString()
ingdc
  • 760
  • 10
  • 16
  • I don't want to use a method. I might wanna do it in an HTML template so I want a really quick and clean shortcut. – Qiimiia Aug 04 '21 at 06:10
  • @Qiimiia Then please add this "don't want to use a method" and "for use in HTML-template" as requirement to your question. (Mentioning ghe templating-language, e.g. Angular, might help there to). – hc_dev Aug 04 '21 at 06:14
0

Lots of ways. A short one without methods is using template strings:

let inputNum = 222;
let newString = `${inputNum}`;
console.log(typeof(newString));
Tushar Shahi
  • 16,452
  • 1
  • 18
  • 39