1

I am trying to do a simple array sort in a directive. But somehow when i put the nested array in the orderBy filter it is losing array and becomes an object (which can not be ordered)

when i log out the scope.item inside the directive it says: addresses: Array[2]

but when trying to filter using $filter('orderBy')(scope.item.addresses, 'distance'); i am getting "TypeError: object is not a function"

(function(angular){
'use strict';
angular.module('starter').directive('getDistance', function() {
    return {
        restrict: 'E',
        replace: true,
        link: function (scope, element, $filter) {

            ;
            console.log(scope.item);

            scope.item.addresses = $filter('orderBy')(, scope.item.addresses, 'distance');

            console.log(scope.item.addresses);
        }
    };
});
})(window.angular);
1
  • You have an extra comma right after '$filter('orderBy')('. Typo? Commented Aug 17, 2014 at 1:13

1 Answer 1

3

You need to inject filter in the directive definision not in the linking function.

angular.module('starter').directive('getDistance', function($filter) {

Or

angular.module('starter').directive('getDistance', ['$filter', function($filter) {..

and do (Removing the extra comma, which probably is a typo):

scope.item.addresses = $filter('orderBy')(scope.item.addresses, 'distance');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.