Angularjs creating filter for directive

I am trying to create filterin angular, which can affect the way data is bound to a directive, similar to how a filter jsoncan be applied to an expression.

I have a lot of problems with this, although it seems that the definition of a filter is not enough to work on anything other than built-in expressions. I am absolutely sure that I have seen this before.

Question

Is it possible to create a filter that works internally with a directive? Like this?

<div ng-directive="Model.Target | filterName"></div>

Update

ng-modelwas just an example. I'm not looking for an existing filter, I'm not looking for how to apply filters, I'm not looking ng-repeat. I specifically want to create a new filter that can work with the directive.

Update 2

, angular ( 154 of filters.js) , . ;

.filter('sample', function () {
    return function (obj) {
        console.log("typoef: ", typeof obj);
    }
});

;

<div data-ng-custom-directive="Model.Tags | sample"></div>

...

Uncaught TypeError: undefined

- , $scope.Model.Tags.

- , ng-model, . ng-model, , ng-repeat, ? , , , , ng-model, , , .

+4
1

, , (). '='. :

HTML

<div ng-init="test = [1,2,3,4,5]">
    <div dir-a="test | limitTo:3"></div>
</div>

JS

.directive('dirA', function() {
    return {
        scope: {
            dirA: '=' // this is important, '@' would not work
        },
        link: function($scope, iElm, iAttrs, controller) {
            console.log('$scope.dirA = ', $scope.dirA);
        }
    };
});

"$scope.dirA = " Array [ 1, 2, 3 ]

+3

All Articles