Defining the Directive View Template

You can include AngularJS template code to build view components that will be displayed in the HTML element that contains the directive. You can add template code directly by using the template property, as in this example:

directive('myDirective', function() {  return {    template: 'Name: {{name}} Score: {{score}}'  };});

You can specify a root element in the custom template—but only one element. This element acts as the root element for any child element defined in the AngularJS template to be placed inside. Also, if you are using the transclude flag, the element should include ngTransclude. For example:

directive('myDirective', function() {  return ...

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.