Answering a general question, yes, you can usually use a user-created filter in common angular expressions. You may have problems with ng-attr due to a parsing error (probably an error in the angular parser). You can still use filters in ng-attr with
<span ng-style="{ 'opacity': (slider | opacity) }">TEXT</span>
ng-attr , although most useful for binding to style objects directly
<span ng-style="sliderStyle">TEXT</span>
You can also customize the style using
<span style="opacity: {{slider|opacity}}">TEXT</span>
with below filter :
app.filter('opacity', function () { return function (input) { return 0.1 * input; }; });
Working jsfiddle
Depending on which solution is better, it mainly depends on where you plan to reuse things. Filters are available in all scope s, but this, in particular, may make sense only for this controller. Remember that reuse can be done using directives (which may have a controller).
source share