从元素属性中获取ng-repeat指令中的orderBy值?

时间:2014-06-26 05:05:13

标签: angularjs

所以我有这个指令:

app.directive('replaceelement', function() {
    return {
        restrict: 'E',
        replace: true,
        scope:true,
        link: function(scope, element, attrs) {
            scope.blockcss = attrs.blockcss;
            scope.sorter = attrs.sorter;

        },
      template:'<div class="{{blockcss}}" ng-repeat="content in something | limitTo:10 | orderByPriority | orderBy:sorter"  ng-include src="blockcss+\'.html\'"></div>'

    }
});

没什么特别的。

这是它应该运行的元素。

<replaceelement blockcss="cssname" sorter="sortby"></replaceelement>

我运行一个简单的ng-click来更改控制器中名为sorter的变量。

Orderby不适用于sorter属性。我有感觉,因为sorter是控制器中的变量,我不能通过从属性传递的名称来调用它?

整天都在努力,无法找到办法。有人可以帮忙吗?

由于

1 个答案:

答案 0 :(得分:0)

ng-repeat中的orderBy专门用于数组。见https://docs.angularjs.org/api/ng/filter/orderBy