0

这就是我想要做的:

ng-include=" 'views/directives/list_elements/'+ list.type.object | listobjects +'.html' "

没有过滤器它工作正常

4

1 回答 1

1

过滤器在表达式内部工作,而ng-include赋值是一个字符串。这就是为什么,您可以ng-init将您想要的值作为特定控制器范围内的 URL 的一部分,然后使用它。

文档

<script>
function Ctrl($scope) {
  $scope.list = [['a', 'b'], ['c', 'd']];
}
</script>
<div ng-controller="Ctrl">
<div ng-repeat="innerList in list" ng-init="outerIndex = $index">
  <div ng-repeat="value in innerList" ng-init="innerIndex = $index">
     <span class="example-init">list[ {{outerIndex}} ][ {{innerIndex}} ] = {{value}};</span>
  </div>
</div>
</div>

对于您的情况,您可以执行以下操作:

ng-init="url_part=list.type.object | listobjects +'.html'"

然后在您的 URL 中使用它。

'views/directives/list_elements/'+url_part

否则,您也可以在控制器中使用相同的过滤器。

于 2014-05-12T07:25:55.240 回答