aboutsummaryrefslogtreecommitdiffstats
path: root/docs/content/error/compile/tplrt.ngdoc
blob: 39e3271f686dcb6b1425bd3660be417dd6c18522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@ngdoc error
@name $compile:tplrt
@fullName Invalid Template Root
@description

When a directive is declared with `template` (or `templateUrl`) and `replace` mode on, the template must have exactly one root element.
That is, the text of the template property or the referenced by the templateUrl must be contained within an html elemen.
For example, '<p>blah blah blah</p>' instead of simply 'blah blah blah'.
Otherwise the replacement operation would result in a single element (the directive) being replaced with multiple elements or nodes, which is unsupported and not commonly needed in practice.


For example a directive with definition:
```
myModule.directive('myDirective', function factory() {
  return {
    ...
    replace: true,
    templateUrl: 'someUrl'
    ...
  }
});
```

And a template provided at URL `someUrl`. The template must be an html fragment that has only a single root element, like the `div` element in this template:
```
<div><b>Hello</b> World!</div>
```

An an invalid template to be used with this directive is one that defines multiple root nodes or elements. For example:
```
<b>Hello</b> World!
```