I try to follow angular's best practice guidelines and use directives to encapsulate reusable HTML elements. Error message:
Error: the template must have exactly one root element. was: partials / user / path / to / somedata.html
directive code:
.directive('stDirectivename', function() { return { restrict: 'E', replace: true,
And the template:
<div ng-show="person.condition" class="someclass"> <span class = "personRoi"> <i class="anotherclass " ng-class="{'specialclass1': person.count>=0,'specialclass2':person.count<0}"> </i>{{person.somedata}}% </span> </div>
Called in partial (which is a modal pattern) as:
<st-directivename></st-directivename>
when i replace url template for plain html line in directive. Everything works. Unfortunately, I cannot do this for a real template that includes both ' and.' In addition, this solution will not scale for larger templates that I plan for some directives.
Also, when I just insert the html template instead of the directive tag, everything works correctly (I actually extract the code from the existing html to make it reusable).
I read in other SO questions that this is related to adding extra space / tags / comments in the template. But I can not find such elements.
Does anyone know a solution for this? I will be happy for any help.
angularjs angularjs-directive
alonisser
source share