Angular JS:orderBy功能不起作用

时间:2013-07-13 07:37:25

标签: angularjs

我的HTML:

    <table class="table">
        <thead>
        <tr>
            <th><a href="">Name</a></th>
            <th><a href="">Issued shares</a></th>
            <th><a href="">Closing price</a></th>
            <th><a href="" ng-click="predicateBlueChip = 'marketCap()'; reverseBlueChip = !reverseBlueChip">Market capitalisation</a></th>
        </tr>
        </thead>
        <tbody>
        <tr ng-repeat="listing in listings | orderBy:predicateBlueChip:reverseBlueChip">
            <td><a ng-href="#/browse/listing/{{ listing.id }}">{{ listing.name_short }}</a></td>
            <td>{{ listing.last_price.issued_shares }}</td>
            <td>{{ listing.last_price.price_close }}</td>
            <td>{{ marketCap(listing) | currency:'R' }}</td>
        </tr>
        </tbody>
    </table>

控制器:

   $scope.predicateBlueChip = 'marketCap()';
    $scope.reverseBlueChip = true;

    $scope.marketCap = function(listing) {
        return Math.round(listing.last_price.price_close * listing.last_price.issued_shares / 1000000);
    }

订单不起作用,我不知道我哪里出错了;关于orderBy的众多其他帖子没有解决我的问题。有什么建议吗?

1 个答案:

答案 0 :(得分:2)

表达式应该是一个函数,而不是包含函数调用的字符串。

删除此行:

$scope.predicateBlueChip = 'marketCap()';

直接使用marketCap函数:

<tr ng-repeat="listing in listings | orderBy:marketCap:reverseBlueChip">