Angularjs防爆pression [英] Angularjs Expression

查看:137
本文介绍了Angularjs防爆pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示从view.I数据的HTML标签有一个数据级别 $ scope.level = < b>我要大胆​​< / b>中当数据在模板给出如下应当尊重html标签以及

I am trying to display the html tags from the data in the view.I have a data level which is $scope.level="<b>i should be bold</b>" and when the data is given in the template as given below should respect the html tag as well

<div ng-controller="MyCtrl" >
{{level}}
</div> 

这是它应该是大胆而无需使用

that is it should be bold without using

<div ng-controller="MyCtrl" id="tableForVxp" class="dataDisplay2">
<b>{{level}}</b>
</div>

不过,与我有什么到目前为止已经试过我不能够才达到it.It也呈现出了view.The问题标​​签在此说明的的jsfiddle 这里

反正是有实现it.or我在这里完全错了?

Is there anyway to achieve it.or am i totally wrong here?

推荐答案

您可以使用 ngBindHtml 指令,它评估前pression并插入生成的HTML到的元素。不要忘了,包括在 ngSanitize 指令。

You can use the ngBindHtml directive which evaluates the expression and inserts the resulting HTML into the element. Don't forget to include the ngSanitize directive.

https://docs.angularjs.org/api/ng/directive/ngBindHtml

例如:

app.js

angular.module('app', ['ngSanitize'])
.controller('Controller', function($scope) {
  $scope.data = '<b>my text</b>'
});

index.html的

index.html

<div ng-controller="Controller">
 <p ng-bind-html="data"></p>
</div>

这篇关于Angularjs防爆pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆