Chris Russo Chris Russo - 3 months ago 18
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="eirana_knows.feedback"></p>
</div>
<br class="clear"/>
</div>


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="eirana_knows.feedback"></p>


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

Kind regards; Chris

Answer

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

var newHTML = angular.element(eirana_knows.feedback); //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
someElement.append(newHTML);

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

Comments