Reputation: 11642
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
Upvotes: 1
Views: 402
Reputation: 43023
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>
Upvotes: 4