2016-01-12 3 views
3

Следующий код всегда оценивает вкладчиков верхнего уровня как истинных asn Contributors как false. Я могу видеть изменение member.price и member.amount? У кого-нибудь есть идея, что я делаю неправильно?ng-show никогда не отображается

<md-virtual-repeat layout-wrap class="toast" ng-repeat="member in members| filter:searchText | orderBy:orderByFunction" > 
    <div class="subtitle" ng-show="parseInt(member.price) <= parseInt(member.amount)" > 
     <h2> CONTRIBUTORS {{member.price}} -- {{member.amount}}</h2> 
    </div> 
    <div class="subtitle" ng-hide="parseInt(member.amount) <= parseInt(member.price)" > 
     <h2> TOP CONTRIBUTORS {{member.price}} -- {{member.amount}}</h2> 
    </div> 

так что я начал так:

<md-virtual-repeat layout-wrap class="toast" ng-repeat="member in members| filter:searchText | orderBy:orderByFunction" > 
            <div class="subtitle" ng-show="showContrib(member) == 1" > 
             <h2> CONTRIBUTORS {{member.price}} -- {{member.amount}}</h2> 
            </div> 
            <div class="subtitle" ng-hide="showTop(member) == 1" > 
             <h2> TOP CONTRIBUTORS {{Number(member.price)}} -- {{Number(member.amount)}}</h2> 
            </div> 
            <md-whiteframe class="md-whiteframe-z3 frieed" style="margin:6px; padding: 19px;" flex-sm="35" flex-gt-sm="25" flex-gt-md="20" layout layout-align="center center"> 
             {{ member.amount}} 
            </md-whiteframe> 
           </md-virtual-repeat> 

с этим JS код:

$scope.showTop = function(member){ 
     if($scope.topShow == 1){ 

      return 0; 
     } 
     if(parseInt(member.price) < parseInt(member.amount)){ 
    console.log('came here price'); 
      $scope.topShow = 1; 
      return 1; 

     } 
     return 0; 

}; 
    $scope.showContrib = function(member){ 
     $scope.conShow = 1; 
//  console.log('price='+member.price+"amount"+member.amount); 
     if($scope.conShow == 1){ 
      return 0; 
     } 
     if(parseInt(member.price) == parseInt(member.amount)){ 
      $scope.conShow = 1; 
      return 1; 

     } 
     return 0; 

}; 

Затем я перейти к первой части, чтобы попытаться устранить.

+0

Я не думаю, что вы можете использовать 'parseInt' в выражении. Это функция JavaScript, а не свойство '$ scope'. – Claies

ответ

3

Вы не можете использовать ParseInt, вместо этого я хотел бы использовать * 1, чтобы сделать его внутр.

<div class="subtitle" ng-show="member.price*1 <= member.amount*1" > 
    <h2> CONTRIBUTORS {{member.price}} -- {{member.amount}}</h2> 
</div> 
+0

Мне нравится * 1, sneak way но полезный – RoliCo

+0

Это ответ, который я использовал для моего первоначального вопроса. Я бы добавил +1 к вам, но моей репутации пока недостаточно. – user3308713

+0

отлично, чтобы помочь вам бросить, пожалуйста, напоминайте, чтобы принять ответ, это тоже нормально :) –

2

parseInt не будет работать на виду.

View работает только с областью видимости.

Создайте метод сравнения по области, а затем вызовите его из представления.

Попробуйте как этот

$scope.isGreater=function(a,b){ 
    return parseInt(a) <= parseInt(b); 
} 

зрения

<div class="subtitle" ng-show="isGreater(member.price,member.amount)" > 
    <h2> CONTRIBUTORS {{member.price}} -- {{member.amount}}</h2> 
</div> 
<div class="subtitle" ng-hide="isGreater(member.amount, member.price)" > 
    <h2> TOP CONTRIBUTORS {{member.price}} -- {{member.amount}}</h2> 
</div> 
0

Вы не можете parseInt как в шаблоне.

В шаблоне контроллера могут использоваться только элементы (функции, переменные), относящиеся к сфере действия контроллера.

Для использования parseInt в шаблоне назначения window объекта, parseInt размаху контроллера:

$scope.parseInt = window.parseInt; 
Смежные вопросы