如何显示  或角度数据中的任何原始html? [英] How to display   or any raw html in angular data?
本文介绍了如何显示  或角度数据中的任何原始html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将
显示为空格而不是字符串.是否有像树枝一样的 raw
过滤器?
{{item}}$scope.item = ' ';
但结果被转义 
.我需要这个,因为 ' '
的高度为 0.
解决方案
使用 ngBindHtml
对于 1.2.x 以上的 Angular 版本:
使用ng-bind-html
html
<div ng-bind-html="item"></div>
脚本
var app = angular.module('myApp', ['ngSanitize']);app.controller('Controller', function ($scope, $sce) {$scope.item = '什么是你的名字?';});
<小时>
对于 Angular 1.0.x 版本:
使用ng-bind-html-unsafe
html
<div ng-bind-html-unsafe="item"></div>
脚本
var app = angular.module('myApp', []);app.controller('Controller', function ($scope) {$scope.item = '什么是你的名字?';});
How can I display
as space not as string. Is there raw
filter like in twig?
<div>{{item}}</div>
$scope.item = ' ';
But the result is escaped &nbsp;
. I need this because ' '
have height of 0.
解决方案
It can be easily done by using ngBindHtml
For Angular above 1.2.x version:
use ng-bind-html
html
<div ng-app='myApp' ng-controller="Controller">
<div ng-bind-html="item"></div>
</div>
script
var app = angular.module('myApp', ['ngSanitize']);
app.controller('Controller', function ($scope, $sce) {
$scope.item = 'What Is Your Name?';
});
For Angular 1.0.x version:
use ng-bind-html-unsafe
html
<div ng-app='myApp' ng-controller="Controller">
<div ng-bind-html-unsafe="item"></div>
</div>
script
var app = angular.module('myApp', []);
app.controller('Controller', function ($scope) {
$scope.item = 'What Is Your Name?';
});
这篇关于如何显示 &nbsp;或角度数据中的任何原始html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文