最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error: [$compile:tplrt] Template for directive 'checkNav' must have exactly one root element - Stac

programmeradmin1浏览0评论

I use meteor+angular, I want use templateUrl in directive to include nav.ng.html
but I throw a error

Error: [$pile:tplrt] Template for directive 'checkNav' must have exactly one root element  

index.html:

 5 <body ng-app='checkApp' ng-controller='CheckCtrl'>
 6   <check-nav></check-nav>
 7 </body>  

directive.js

  1 angular.module 'checkApp'
  2   .directive 'checkNav', () ->
  3   ┊ restrict: 'E'
  4   ┊ replace: true
  5   ┊ templateUrl: 'client/templates/check-views/nav.ng.html'

nav.ng.html

<div>test</div>

how can I fixed it?

I use meteor+angular, I want use templateUrl in directive to include nav.ng.html
but I throw a error

Error: [$pile:tplrt] Template for directive 'checkNav' must have exactly one root element  

index.html:

 5 <body ng-app='checkApp' ng-controller='CheckCtrl'>
 6   <check-nav></check-nav>
 7 </body>  

directive.js

  1 angular.module 'checkApp'
  2   .directive 'checkNav', () ->
  3   ┊ restrict: 'E'
  4   ┊ replace: true
  5   ┊ templateUrl: 'client/templates/check-views/nav.ng.html'

nav.ng.html

<div>test</div>

how can I fixed it?

Share Improve this question edited Jul 8, 2015 at 15:23 nataila asked Jul 8, 2015 at 15:16 natailanataila 1,6194 gold badges20 silver badges26 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

This results from the fact the the HTML your directive is rendering (nav.ng.html) has sibling elements instead of one that wraps all.

For instance, this will result in the error:

<div>One</div>
<div>Two</div>

This will be fine:

<div>
    <div>One</div>
    <div>Two</div>
</div>

So you should fix the HTML to have only one root element and the error will go away.

your nav.ng.html should look like this:

<div>
  <div>test</div>
</div>

if it not works? then also change index.html as:

<body ng-app='checkApp' ng-controller='CheckCtrl'>
  <div>   
     <check-nav></check-nav>
  </div>
 </body>  

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论