Sunday, 15 September 2013

angularjs - Passing filter as an angular directive param -



angularjs - Passing filter as an angular directive param -

i pass w filter param custom directive in app. like:

usage in application:

<my-directive data='datavariable' datafilter='numericfilter: 123'/>

directive template:

<span> {{ info | datafilter }} </span>

directive:

... scope: { data: '=', datafilter: '@' } ...

when shwon above error related syntax (: not recognized), dependency injection (filter not found) or filter nothing.

you can dynamically filter want using filter service:

angular.module('app').directive('mydir', ['$filter', function($filter) { .... link: function($scope, $el, $attr) { var desiredfilter = $filter($attr['datafilter']); //desiredfilter function run filter passed, throw exception if filter not found } }

i hope helps.

angularjs angularjs-directive angular-filters

No comments:

Post a Comment