0

I have an angular project that will be loading external HTML from a string variable into a div that currently has a controller scoped to it.

The HTML that I will be loading from the var will have angular bindings in the html. Once loaded the bindings don't seem to work. I'm wondering how I get angular to recognize the new HTML and parse the bindings so that content renders properly.

Right now the HTML loads but I end up seeing things like {{myvar}} render as text and not render the scoped variables.

1
  • Could you post your code please? Check your browser console as well. If something like the controller fails to bind properly, you'll see an error in the console and this sort of behavior in your output. Commented Oct 10, 2013 at 20:32

2 Answers 2

1

You need to do manually what angular does automatically inside ng-view directive. Something like along those lines should do the trick:

var html = '...';
var linker = $compile(html); // compile html
var element = linker($scope, function () { // remember to pass correct scope here
}); // link compiled html with scope
$('.target-div').append(element);
Sign up to request clarification or add additional context in comments.

Comments

0

Output to your element like this:

<p ng-bind-html="myvar.name"></p>

Comments

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.