0

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

2
  • didn't get what exactly you want, but going by the example, <p ng-bind="2 + 2"></p> works fine Commented Aug 13, 2016 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" Commented Aug 14, 2016 at 22:44

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

7 Comments

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.
You won't be able inject javascript that way as it is a huge security risk to inject and run arbitrary javascript.
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.
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/…
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
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.