After organizing all the strings from my code, I compiled them into a file named constants.ts
.
export class Constants {
public static API_URL = '/api/';
public static CREATE_CHILD_API_URL = Constants.API_URL + '%s' + '/create-child';
}
I have successfully substituted a value into the string using console.log
:
import { Constants } from '../common/constants';
console.log(Constants.CREATE_CHILD_API_URL, 'dummyId');
This results in: /api/dummyId/create-child
, which is what I aimed for.
Now, how can I achieve the same but store the result in a variable for future use?
Is there a native solution that works on modern browsers without requiring external libraries?
It seems like Template literals
are not suitable for this scenario since the variable won't be defined in my constants file.