【问题标题】:Typescript populate string template from appsettingsTypescript 从 appsettings 填充字符串模板
【发布时间】:2019-04-03 20:54:15
【问题描述】:

想法是在 appSettings.json 中有一个模板字符串:

"AppSettings": {
    "PretendUri": "http://devEnvSite/blahBah/{0}/get",
     ...

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

然后我想在几个控制器中使用 PretendUri 属性,这些控制器在运行时用有意义的/动态值填充了 {0}。

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

有什么建议吗?

【问题讨论】:

    标签: angular typescript string-formatting string-interpolation


    【解决方案1】:

    字符串替换

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

    或者可能在您的代码中,例如:

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

    【讨论】:

      猜你喜欢
      • 2017-02-23
      • 2017-04-04
      • 1970-01-01
      • 2010-10-19
      • 1970-01-01
      • 1970-01-01
      • 2013-06-06
      • 1970-01-01
      相关资源
      最近更新 更多