2016-11-19 28 views
2

我在表格中有简单的角度指令,但它在表格之前呈现。角度指令不在正确的位置

app.directive('myDirective',function() { 
 
    return { 
 
    restrict : "E", 
 
    templateUrl : "directives/myDirectiv.html", 
 
    replace : true 
 
    } 
 
})
<table class="table"> 
 
      <thead> 
 
      <tr> 
 
       <th>ID</th> 
 
       <th>Name</th> 
 
       <th>Deposit</th> 
 
       <th>Credit Card</th> 
 
      </tr> 
 
      </thead> 
 
      <tbody> 
 
      <my-Directive></my-Directive> 
 
      </tbody> 
 
    </table> 
 

 

 
<!-- here is html in the directive --> 
 

 
<tr> 
 
    <td>001</td> 
 
    <td>Danilo</td> 
 
    <td>7163547265</td> 
 
    <td>Visa</td> 
 
</tr>

如何解决它是在正确的地方。 Ty提前。

回答

0

你不能把custom-elementtbody元素中。如果你在tbody里面添加自定义元素,它会认为这个自定义元素会被抛出无效的html &。

应该转换指令类型来限制A(属性),而不是E(元素)。现在把你的指令放在tbody元素上。

指令

app.directive('myDirective',function() { 
    return { 
    restrict : "A", //<-- converted E to A 
    templateUrl : "directives/myDirectiv.html", 
    //replace : true //it isn't needed, though this has been deprecated since 1.5+ 
    } 
}) 
+0

泰快速的答案。我看到这个评论指令也很好。 – Danilo

+0

@Danilo我看到评论它会工作。但人们通常不喜欢使用它。接受答案,如果它确实帮助你,谢谢:) –

+0

@达尼洛提醒,请接受答案:) –