使用ng-bind-html仅转换特定标签

时间:2016-12-09 15:36:10

标签: html angularjs laravel tinymce ng-bind-html

我正在使用文本编辑器TinyMCE,我试图在从数据库中检索数据时将code与一般描述区分开来。它就像StackOverflows编辑器一样。但是,我可以使用ng-bind-html转换所有 html标记,这是主要问题。我不想转换code部分。 例如:

<strong>hello</strong>
<code>
     <div>i dont want the tags inside code to be converted</div>
     <p>i am para</p>
</code>

所需的输出是:

你好

<code>
     <div>i dont want the tags inside code to be converted</div>
     <p>i am para</p>
</code>

但是,我使用ng-bind-html获得的输出是:

&#34; 的你好

我不希望转换代码中的代码

我是para。&#34;

我正在使用angular 1.52laravel php

我的部分:

<div ng-bind-html="myResult">

</div>

后端控制器:

public function getquesdet(){
    $id = Request::input('id');

    $data= Data::where('id','=',$id)->first();
    $body = html_entity_decode($data['body']);

    return html_entity_decode($body);

}

我的angularjs控制器:

app.controller('seperatequestion',['$scope','$rootScope','$http','$stateParams',function($scope,$rootScope,$http,$stateParams){
$http({
    method:'GET',
    url : $rootScope.apiend + '/getquestiondet',
    params:{
        id:$stateParams.qid
    }
}).success(function(result){
    $scope.myResult= result;

}).error(function(data){
    console.log(data);
})

}])

所以,我想要的是转换html标签,排除code标签内的标签。

1 个答案:

答案 0 :(得分:0)

TinyMCE已经有一个插件来解决你想要做的事情:

https://www.tinymce.com/docs/plugins/codesample/

请注意,当您在TinyMCE之外呈现内容时,您需要在渲染页面中包含Prism(http://prismjs.com/index.html)以获得相同的外观。