簡體   English   中英

角JS自定義指令不起作用

[英]angular JS custom directive not working

app.directive("myData", function()
{
    return {
        templateUrl: '/my-data.html'
    };

});
my-data.html file code

<tr ng-repeat="employee in employees">
    <td>{{employee.id}}</td>
    <td>{{employee.name}}</td>
    <td>{{employee.gender | uppercase }}</td>
    <td>{{employee.salary | currency : '$'}}</td>
</tr>


<body ng-app="DemoAngular">
    <div ng-controller="AngularController">

        <table>
            <thead>
                <tr>
                    <th>Id</th>
                    <th>Name</th>
                    <th>Gender</th>
                    <th>Salary</th>
                </tr>
            </thead>
            <tbody>
                <my-data></my-data>
</tbody>
        </table>


    </div>
</body>

自定義指令reg,指令模板html文件分配,在表主體中調用自定義指令,還在標頭中添加了腳本文件位置。 什么都沒有填充/不工作..需要幫助謝謝

myData將不會在table元素中識別。 您可以使用restrict: 'A'更改指令,並在模板中使用它,如下所示:

<table>
  <thead>
  ...
  </thead>
  <tbody>
    <tr my-data></tr>
  </tbody>
</table>

UPD:

在您的指令中添加replace:true

演示朋克

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM