Difference In $interpolate Between Angularjs 1.0 And 1.2
I'm writing a filter to format addresses in a single line. The object that will be passed into the filter has the format: { Line1: '123 Main St.', Line2: 'Apartment 2', // Opti
Solution 1:
I realized that before I upgraded to 1.1.5, my workaround to using a ternary operator in interpolated expressions was to use &&
and ||
(like someCondition && TruthyResult || FalseyResult
) to effectively get the same result. Here's how you'd apply it to your code:
template='{{Line1}}, {{Line2 && (Line2 + \', \') || \'\'}}{{City}}{{State}}{{Zip}}';
DEMO:http://jsfiddle.net/f9n6r/
The only problem with this setup is if the the TruthyResult
doesn't actually return something truthy, the FalseyResult
will be returned (just the nature of using &&
and ||
like this, compared to the ternary operator). In your code though, (Line2 + \', \')
will never be falsey because of the \', \'
, so it won't be a problem here. But in a more general case, it could be.
Post a Comment for "Difference In $interpolate Between Angularjs 1.0 And 1.2"