That is my question, what are the pros and cons ?
In my app I am using interpolation but I get errors like this
{{::sport.name}}
-> NHL Futures & Props
and if I use ng-bind-html
ng-bind-html="sport.name"
-> NHL Futures & Props
in this case ng-bind-html
is doing what I want. But, is there something wrong with it ?
Is there one better than the other ?
so tell me, I am open to suggestions.
In this article, you will learn about interpolation data binding in Angular. This article will explain interpolation binding in an Angular application. Angular Interpolation is used to achieve one-way data binding from component to the View template.
Definition and Usage. The ng-bind-html directive is a secure way of binding content to an HTML element. When you are letting AngularJS write HTML in your application, you should check the HTML for dangerous code.
Data binding allows for dynamism and interactivity in applications. There are about four types of data binding available in Angular: Event binding: This data binding type is when information flows from the view to the component when an event is triggered.
Definition and Usage The ng-bind-html directive is a secure way of binding content to an HTML element. When you are letting AngularJS write HTML in your application, you should check the HTML for dangerous code. By including the "angular-sanitize.js" module in your application you can do so by running the HTML code through the ngSanitize function.
Actually the main difference between ng-bind and ng-bind-html is the usecase. ng-bind will just display the text interpretation of your variable but ng-bind-html will interpret the html in your variable.
Let say we have a variable in your scope
$scope.myText = "<b>Hi</b>";
ng-bind or {{}} would display
<b>Hi</b>
ng-bind-html would display
Hi
Another precision is that ng-bind-html can sanitize your html to prevent code injection.
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