gpt4 book ai didi

javascript - 如何用 Angular 替换功能替换字符?

转载 作者:行者123 更新时间:2023-11-29 16:55:29 25 4
gpt4 key购买 nike

我想将 html 字符串中的字符 {} 替换为 {{}}我正在使用替换功能,但出现以下错误:

$scope.selectedtemplate.template.replace  is not a  function

我的代码

 $scope.selectedtemplate.template = $scope.selectedtemplate.template.replace("{" , "{{" ) ;
$scope.selectedtemplate.template = $scope.selectedtemplate.template.replace("}" , "}}" ) ;

template是HTML字符串

最佳答案

这是一个例子:http://fiddle.jshell.net/33tom882/2/

您可能收到“replace is not a function”错误,因为 $scope.selectedtemplate.template 未定义或不是类型字符串。有关 string.replace 函数的更多信息,请参见此处:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

不过,似乎有更好的方法来解决您的实际问题,即使用 Angular $scope 属性来管理您的变量,而不是直接将 HTML 修改为字符串。

关于javascript - 如何用 Angular 替换功能替换字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32465972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com