2013-11-15 4 views
1

У меня есть угловая директива, которая сортирует столбцы в таблице. до версии 1.20 это сработало, но после обновления до 1.20 я получаю следующую ошибку. Кто-нибудь знает, что не так?Неизвестная угловая ошибка при использовании директивы сортировки

Error: [$parse:isecprv] http://errors.angularjs.org/undefined/ $parse/isecprv?p0=_sort()

app.directive('sorted', function() { 
    return { 
     scope: true, 
     transclude: true, 
     template: '<a href="#/" ng-click="_sort()" ng-transclude=""></a>' + 
      '<span class="sortArrow" ng-show="show_sort_icon(true)">&#x25BC;</span>' + 
      '<span class="sortArrow" ng-show="show_sort_icon(false)">&#x25B2;</span>', 
     controller: function ($scope, $element, $attrs) { 

      $scope._sort = function() { 
       $scope.model.sort($attrs.sorted); 
      }; 

      $scope.show_sort_icon = function (is_desc) { 
       return ($scope.model.sidx == $attrs.sorted) && ($scope.model.is_desc == is_desc); 
      }; 
     } 
    }; 
}); 

Использование:

<table> 
    <thead> 
     <tr> 
      <th sorted="something">Something</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr ng-repeat="item in model.items"> 
      <td>{{item.something}}</td> 
     </tr> 
    </tbody> 
</table> 

enter image description here

+0

Вы можете воспроизвести эту ошибку в Plunker/Fiddle? –

+0

@MaximShoustin Я попробую и отправлю обратно. – Grant

+0

Пожалуйста, предоставьте jsfiddle. Один вопрос: почему вы не используете фильтр OrderBy? В чем преимущество – tschiela

ответ

0

Ответ найден @Heikki

Fields with names that begin or end with an underscore are considered private fields. Angular expressions are not allowed to reference such fields on the scope chain. This only applies to Angular expressions (e.g. interpolation and calls to $parse with a string expression argument) – Javascript itself has no such notion.

To resolve this error, use an alternate non-private field if available or make the field public (by removing any leading and trailing underscore characters from its name.)

Example expression that would result in this error:

<div>{{user._private_field}}</div> 
Смежные вопросы