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.
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?'; }); $scope.item = $sce.trustAsHtml('What Is Your Name?');For Angular 1.3.x version:
Use the $sce service to mark the string as safe to use in a specific context (HTML in this case).
See the documentation here
HTML code:
<div ng-app='myApp' ng-controller="Controller"> <div ng-bind-html="item"></div> </div> JS code (controller):
var app = angular.module('myApp', []); app.controller('Controller', function ($scope, $sce) { $scope.item = $sce.trustAsHtml('<span>Some HTML code</span>'); }); You can also create a filter for that.
Filter
app.filter("trustHtmlContent", ['$sce', $sce => htmlCode => $sce.trustAsHtml(htmlCode)]); usage
<ANY ng-bind-html="value | trustHtmlContent"></ANY> src: How do you use $sce.trustAsHtml(string) to replicate ng-bind-html-unsafe in Angular 1.2+
You can use the ascii code for   in a string. Alt-255.
This will correctly render as an  .
<, > or it's obvious that you can insert any character into text.