angularjs自定义令牌替换

时间:2018-08-26 22:50:02

标签: javascript angularjs regex

我有以下字符串:

$scope.testStr = "This is my {test} string that needs {custom} token replacement";

我需要使用自定义令牌替换进行处理,如下所示:

$scope.test = "Test Text";
$scope.custom = "More Text";

这样,当我按如下所示绑定字符串时:

<p>{{testStr}}</p>

它将这样输出:

<p>This is my Test Text string that needs More Text token replacement</p>

我相信正则表达式可能是处理此自定义令牌替换的我的选择,但我似乎无法弄清楚该如何处理。我将需要使它具有动态性,因为替换令牌的变量将动态变化。预先感谢!

0 个答案:

没有答案