Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs ng重复和多态指令_Angularjs_Angularjs Directive - Fatal编程技术网

Angularjs ng重复和多态指令

Angularjs ng重复和多态指令,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我想知道是否有一种方法可以构建一个自定义元素指令,以这种方式与ng repeat一起使用: <div class="list"> <my-custom-directive class="item item-icon-right" ng-repeat="a in concepts"> <p>{{::a.label}}</p> <i class="icon ion-forward muted"&

我想知道是否有一种方法可以构建一个自定义元素指令,以这种方式与ng repeat一起使用:

<div class="list">
      <my-custom-directive class="item item-icon-right" ng-repeat="a in concepts">
          <p>{{::a.label}}</p>
          <i class="icon ion-forward muted"></i>
      </my-custom-directive>
</div>
如果a.href存在,我的自定义指令应该在锚点中编译,如果不存在,应该在段落中编译


问题基本上只是设计:我有一些没有href的项目,但它们应该仍然在列表中。在Ionic1中,看起来我可以创建div列表或a列表,但在不破坏列表设计的情况下不会混淆。

当然可以。大概是这样的:

<my-custom-dir ng-repeat="a in concepts"></my-custom-dir>
以及custom.html模板

<p ng-hide="a.href">{{::a.label}}</p>
<a ng-href="{{a.href}}" ng-show="a.href">{{::a.label}}</a>
<i class="icon ion-forward muted"></i>

尽管如此,我认为您应该能够在.list中有一个带有ng repeat的div.item。在div.item中,你应该可以得到你想要的任何东西不确定ionic1如何处理这个问题,尽管

你看到指令的transclude属性了吗?为它创建一个自定义指令不是一件过分的事吗?你不能有两个ng show来检查并相应地显示吗?@tanmay应该变异的是迭代本身的元素,而不是某个子元素。我之所以处于这种情况,是因为在div.list和a.item或div.item之间添加任何DOM元素都会破坏Ionic1中的列表设计。是的,谢谢。我确实认为爱奥尼亚可以解决这个问题,我会深入研究
<p ng-hide="a.href">{{::a.label}}</p>
<a ng-href="{{a.href}}" ng-show="a.href">{{::a.label}}</a>
<i class="icon ion-forward muted"></i>
$scope.concepts = [{
    href: 'eample.com',
    label: 'example'
  }, {
    label: 'example1'
  }, {
    href: 'eample2.com',
    label: 'example2'
  }]