Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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

share|improve this question
    
didn't get what exactly you want, but going by the example, <p ng-bind="2 + 2"></p> works fine – Aks1357 Aug 13 at 19:40
    
when the information from the ng-bind comes from a function, let's say, grabbed from database, it doesn't show the same behaviour. It would actually print "2+2" instead of "4" – Chris Russo Aug 14 at 22:44
up vote 1 down vote accepted

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

share|improve this answer
    
shows up this way, but it's not being executed. I'm loading the variable eirana_knows.feedback with "<script type="text/javascript">alert(123);</script>" from the database. To test... but no luck so far. – Chris Russo Aug 14 at 23:07
    
You won't be able inject javascript that way as it is a huge security risk to inject and run arbitrary javascript. – mcgraphix Aug 14 at 23:56
    
I'm sure there's a way, and I don't see any security issue with that, the code is coming from my database itself, there's a few big companies doing the same if you look around. – Chris Russo Aug 15 at 0:00
    
You won't be able to do it with just Angular. You would need to do some hoop jumping with jQuery. See this SO article: stackoverflow.com/questions/17460982/… – mcgraphix Aug 15 at 13:08
    
haha, yes, I've seen it, but isn't it ridiculous? I'm using angular because I don't wanna use Jquery, and then I finally have to use Jquery to process an angular response... lol – Chris Russo Aug 15 at 17:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.