指令数组元素未在表格中显示

时间:2017-11-05 11:20:58

标签: javascript angularjs

In this plunk我有一个带有ng-repeat的表,其中表中的一个元素是一个指令。问题是指令字段没有显示在表中。这段代码出了什么问题?

HTML

    <table border="1">
      <tr ng-repeat="row in rows">
        <td>
            {{row.x}}
        </td>            
        <td>
            <div some-directive field="row.field"></div>
        </td>            
      </tr>
    </table>

的Javascript

var app = angular.module('app', []);

app.controller('myCtl', function($scope) {

    $scope.rows = [{x: 1}, {x:2}];

});

app.directive('someDirective', function () {

    var directive = {};

    directive.restrict = 'EA';

    directive.scope = {    
            field: '='
    };

    directive.link = function (scope, element, attrs) {
      scope.field = "aaa";
    };

    return directive;
});

1 个答案:

答案 0 :(得分:0)

答案是添加directive.template =“{{field}}”;