Why this return a blank string on my template?
{{ selectedVehicle.air_conditioning.replace(true, "Yes") }}
The replace() method can be used to search the particular character(s), which is getting replaced with a specific character(s) & return a new generated string. Syntax: string. replace(char findChar, char replacedChar);
replace() Parameters The replace() method can take maximum of 3 parameters: old - old substring you want to replace. new - new substring which will replace the old substring. count (optional) - the number of times you want to replace the old substring with the new substring.
To replace all occurrences of a string in TypeScript, use the replace() method, passing it a regular expression with the g (global search) flag. For example, str. replace(/old/g, 'new') returns a new string where all occurrences of old are replaced with new .
Template strings are a powerful feature of modern JavaScript released in ES6. It lets us insert/interpolate variables and expressions into strings without needing to concatenate like in older versions of JavaScript. It allows us to create strings that are complex and contain dynamic elements.
.replace
method can't be applied on Boolean variable, it works on string only.
That's why you need to convert it to string then apply replace.
{{ selectedVehicle.air_conditioning.toString().replace(true, "Yes") }}
Working Fiddle
Hope this could help you. Thanks.
Okay, if I get it:
you can just use ternary syntax like this:
{{ selectedVehicle.air_conditioning ? "Yes" : "No }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With