无法在 ng-repeat(ng-repeat)内打印范围变量



我正在尝试在ng-repeat循环中关联id。有人可以建议我该怎么做吗?

这是代码

<li ng-repeat="agent in agents">
     <chart chart-id={{agent}}></chart>
</li>

注意:图表是我的指令。

假设你的指令看起来像这样:

app.directive('chart', function() {
   return {
       restrict: 'E',
       replace: true,
       scope: {
           chartId: '='
       },
       template: '<div>Agent {{chartId.name}} reporting for duty</div>'
   }
}

您只需要更新代码,删除大括号并添加引号:

<li ng-repeat="agent in agents">
    <chart chart-id="agent"></chart>
</li>

最新更新