Using filters inside a ternary operator in AngularJS

Is there a way to apply a filter to a variable in a template when it is part of a triple operation?

<img ng-src="{{ image_url && image_url|filter:"foo" || other_url }}"> 

In this case, the filter is a custom filter, but one that I do not want to change to handle the triple operation (since the filter may differ depending on where it was used, and I do not want to redefine this logic a bunch of times).

+4
source share
1 answer

Liviu T. is probably right in most cases: you want to create a function in an area that returns the data you need in this case.

Thus, you can work around by wrapping the filtered expression in parens:

 image_url && (image_url | filter:"foo") || other_url 

Fiddle

+9
source

Source: https://habr.com/ru/post/1486347/


All Articles