Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-bind-html vs {{interpolation}}

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.

like image 916
Non Avatar asked May 13 '15 14:05

Non


People also ask

What is interpolation data binding in angular?

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.

What is ng-bind-HTML in angular?

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.

What is data binding in angular?

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.

What is the ng-bind-HTML directive?

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.


1 Answers

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.

like image 187
Okazari Avatar answered Oct 05 '22 22:10

Okazari