Chris Russo Chris Russo - 2 months ago 4x
AngularJS Question

angular ng-bind-html ng-bind more angular code?

Hello, a simple Angular question, I have:

<div class="_minimal_size margin_10_middle">
<div class="_50 espaciado_0_20">
<p ng-bind-html=""></p>
<br class="clear"/>

If I bind HTML information, works perfectly fine. Now, What I'm tring to do, is to bind, actually angular code, such as {{2+2}} to give an example.

So, is there any way to make this kind of binding possible? If so, I'm looking for a simple approach, such as modifying this line:

<p ng-bind-html=""></p>

For something that allows me to bind angular and process it.

Kind regards; Chris


If you are trying inject angular code, you will want to use the $compile service:

var newHTML = angular.element(; //assuming this html
$compile(newHTML)($scope); //you would need to do this in a directive or controller where you have a scope
//then append the compiled html

Once you compile and inject the HTML, it will process any angular directives that are used in that HTML