2013-07-13 3 views
1

를 작동하지 않는 나의 HTML :각도 JS : 해 orderBy 기능

<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이 작동하지 않으며, 내가 잘못된거야 어디 확실하지 않다; orderBy에 대한 수많은 게시물이 내 문제를 해결하지 못했습니다. 어떤 제안?

답변

2

표현식은 함수 여야하며 함수 호출을 포함하는 문자열이 아니어야합니다.

이 줄을 제거

$scope.predicateBlueChip = 'marketCap()'; 

을 직접 marketCap 기능 사용 : 나뿐만 아니라 다른 헤더를 정렬 할 수 있도록하려면

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

을 (난 그냥 피하기 위해 그것을 꺼내서 혼동). 따라서 orderBy는 범위의 조건부 속성이어야합니다. marketCap을 작동시키기위한 술어에 어떻게 할당합니까? – Tjorriemorrie

+0

'$ scope.predicateBlueChip = $ scope.marketCap;'(그러나이 줄은'$ scope.marketCap'이 정의 된 후에 이루어져야합니다.) –

+0

감사합니다, 완전성을 위해 : 'ng-click = "술어 = marketCap;과''와'$ scope.predicate = $ scope.marketCap;'는 작동합니다. (블루칩을 제거했습니다.) {{marketCap (listing) | currency : – Tjorriemorrie