I'm trying to display a string in my model that contains the html representation of a special character. Unfortunately, it doesn't show that actual character, and I don't know how to make it do it...
this is the code:
<div ng-controller="MyCtrl">
Hello, {{namea}}!
<br/>
<
</div>
<script>
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.namea = 'Superhero <';
}
</script>
this is the output:
Hello, Superhero <!
<
here is a jsfiddle for that
The $ in AngularJs is a built-in object.It contains application data and methods.
In HTML, special characters are typically those that can't be easily typed into a keyboard or may cause display issues if typed or pasted into a web page. If you plan to use any of the special characters on this page, you should use either the HTML entity name or the HTML entity number.
I ran into this problem today. Using AngularJS, in data inside a controller, I was trying to include a string with 'n' with tilde. I tried "Español" as well as the html representation, and neither displayed the desired output.
A coworker helpfully pointed out that unicode works. So I tried
{
name : "my site en Espan\u00F1ol"
}
which gave me
my site en Español
as desired. Check out http://unicode-table.com/en/
You can use ng-bind-html-unsafe directive:
<div ng-controller="MyCtrl" ng-bind-html-unsafe="'Hello,' + namea">
</div>
Check out the examples in the docs and the jsfiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With