Typescript 从 appsettings 填充字符串模板

Typescript populate string template from appsettings

想法是在 appSettings.json:

中有一个模板字符串
"AppSettings": {
    "PretendUri": "http://devEnvSite/blahBah/{0}/get",
     ...

原因是这个 Uri 因环境而异。

然后我想在多个控制器中使用 PretendUri 属性,并在 运行 时用 meaningful/dynamic 值填充 {0}。

在 C# 中,我通常使用 String.Format() 但我发现在 Typescript 中情况并非如此,我需要使用插值。

有什么建议吗?

字符串替换?

"http://devEnvSite/blahBah/{0}/get".replace(/{.*}/, "myCustomValue")

或者可能在您的代码中,类似于:

appSettings.PretendUri.replace(/{.*}/, "myCustomValue")