1

Why this throws an exception?

var item = {ID: 2, Name: "Andrej" };
var html = "<div>{{ID}} - {{Name}}</div>";
$compile(html)(item); // THIS THROWS EXCEPTION

Exception is (line 764)

TypeError: jqLite("<div>").append(element).html().match(/^(<[^>]+>)/) is null
1
  • @Andy Joslin, 1) can $interpolate take scope objects?. 2) If i use $interpolate on a template string with some object or scope object as context, will the template updates as i change that context? +1 for the distinction bw $compile and $interpolate. Sorry i could not use "@Andy Joslin" in answer section. SO is automatically removing it Commented Apr 24, 2013 at 3:11

1 Answer 1

4

If you just want to substitute values using the angular interpolator with an object, use $interpolate.

$compile is made for creating angularized elements, and requires a scope.

var item = {ID: 2, Name: "Andrej" };
var html = "<div>{{ID}} - {{Name}}</div>";
console.log($interpolate(html)(item)); // --> <div>2 - Andrej</div>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.