Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将括号替换为小于个字符的HTML_Javascript_Angularjs_Replace - Fatal编程技术网

Javascript 将括号替换为小于个字符的HTML

Javascript 将括号替换为小于个字符的HTML,javascript,angularjs,replace,Javascript,Angularjs,Replace,我使用AngularJS,代码如下: return text.replace("[", "<"); HTML代码 我添加了这个,它是一个值和一个过滤器 {{post.rating.html | replace_brackets }} 我试着用 但它什么也没给怀特。没有错误但没有输出。请尝试此操作 <div ng-bind-html-unsafe="post.rating.html | replace_brackets"></div> html <d

我使用AngularJS,代码如下:

return text.replace("[", "<");
HTML代码

我添加了这个,它是一个值和一个过滤器

{{post.rating.html | replace_brackets }}
我试着用


但它什么也没给怀特。没有错误但没有输出。

请尝试此操作

<div ng-bind-html-unsafe="post.rating.html | replace_brackets"></div>
html

<div  ng-app='MyApp' ng-controller="PostsCtrl">
<div ng-bind-html-unsafe="test | replace_brackets"></div>
</div>

脚本

var app = angular.module("MyApp", [])
.filter('replace_brackets', function($compile){
    return function(text) {
        var output = text.replace(/\[/g,'<').replace(/\]/g,'>');

        return output;
    };
});

app.controller("PostsCtrl", function($scope) {
    $scope.test = "[div class='rating-container']Visible[/div]";
});
var-app=angular.module(“MyApp”,[])
.filter('replace_括号',函数($compile){
返回函数(文本){
var输出=text.replace(/\[/g',);
返回输出;
};
});
应用控制器(“PostsCtrl”,功能($scope){
$scope.test=“[div class='rating-container']可见[/div]”;
});

显示
文本的内容
@NidhishKrishnan添加了“文本的内容”
ng bind html
是您正在寻找的内容。您还需要将
$sce
注入您的过滤器,并让它返回
$sce.trustAsHtml(您的htmltext);
。我使用这个{{post.rating.html |替换括号}但是你做了一点不同。你的解决方案在JSFIDLE中工作。我的不工作。在这种情况下,我可能需要改变我使用angularjs的方式。你能给我一个JSFIDLE,并告诉我你想要做什么一个JSFIDLE。出于某种原因,它不会转换{{要编写代码,但希望您仍然可以看到我正在尝试做的事情。几乎可以,但它的工作方式与预期不一样。小于字符在您的上一个小提琴中可见。它应该是html字符。
var app = angular.module("MyApp", [])
.filter('replace_brackets', function($compile){
    return function(text) {
        var output = text.replace(/\[/g,'<').replace(/\]/g,'>');

        return output;
    };
});

app.controller("PostsCtrl", function($scope) {
    $scope.test = "[div class='rating-container']Visible[/div]";
});