【问题标题】:How to get ng-repeat item inside transcluded template?如何在嵌入模板中获取 ng-repeat 项目?
【发布时间】:2015-09-14 20:37:21
【问题描述】:

如何在嵌入模板中使用 ngRepeat 项目?有可能吗?

指令模板:

<ng-transclude ng-repeat="record in records | filter1 | filter2"></ng-transclude>

指令:

  app.directive('myDirective', function () {
    return {
      templateUrl: '/views/directives/mydirective.html',
      restrict: 'A',
      transclude: true,
      scope: {
        records: '='
      }
    };
  });

控制器视图:

<div my-directive records="myRecords">
  {{ myDirective.record }}
</div>

【问题讨论】:

  • @Jony-Y,谢谢,我已经看过这个问题,但我需要在指令中隐藏 ngRepeat
  • 为什么还需要使用 transclude?要么将其设为 E 指令并将其放入 div 中,要么将模板附加到 div 并手动创建它...没有理由转入

标签: angularjs angularjs-directive angularjs-ng-repeat angularjs-ng-transclude


【解决方案1】:

从你做的方式看起来不像。

但是你可以通过$compile指令中的模板来实现这一点。

http://jsbin.com/mirisixodo/edit?html,js,console,output

【讨论】:

    猜你喜欢
    • 2016-05-07
    • 2013-03-03
    • 2014-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多