如何显示  或角度数据中的任何原始html? [英] How to display   or any raw html in angular data?

查看:31
本文介绍了如何显示  或角度数据中的任何原始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 &nbsp; as space not as string. Is there raw filter like in twig?

<div>{{item}}</div>

$scope.item = '&nbsp;';

But the result is escaped &amp;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

Working Demo

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&nbsp;Is&nbsp;Your&nbsp;Name?';
});


For Angular 1.0.x version:

Working Demo

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&nbsp;Is&nbsp;Your&nbsp;Name?';
});

这篇关于如何显示 &amp;nbsp;或角度数据中的任何原始html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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