I wrote a directive like this:
app.directive('headersort', function () { return { restrict: 'E', scope: { sortBy: '=', title: '=' }, template: '<th>{{ title }}</th>', replace: true, link: function (scope, element, attributes) { scope.sortBy = attributes.sortBy; scope.title = attributes.title; } }; });
And I use it as follows:
<headersort sortBy="Name" title="Product">
I want <headersort sortBy="Name" title="Product"> be replaced with <th>Product</th> . But I get an error message:
Template must have exactly one root element. was: <th>{{ title }}</th>
But I have one root element, right? My root element is <th> , so why does angular throw this error? What are the conditions / definition of the root element?
source share