How do I replace the value of an element with some compiled HTML

If I compile some HTML with Angular, how can I replace the contents of an DOM element with the compiled HTML? Example:

var html = "<div>{{msg}}</div>";
var scope = $scope.$new();
var scope.msg = "Hello World!";
var linkFn = $compile(html);
var contents = linkFn(scope);

element.replaceContents(contents);//what is the actual syntax for this?

Upvotes: 0

Views: 64

Answers (2)

Timothy Kanski
Timothy Kanski

Reputation: 1888

The pure-javascript way is element.innerHTML = contents;

Upvotes: 0

ArcSine
ArcSine

Reputation: 644

You want to remove the content from the element and append the newly compiled contents.

element.empty().append(contents)

Upvotes: 1

Related Questions