frapontillo / angular-filters

A collection of useful filters for AngularJS.
Apache License 2.0
92 stars 17 forks source link

Support for custom last separator in join filter #4

Closed nonplus closed 10 years ago

nonplus commented 10 years ago

When using the join filter, sometimes I'd like to be able to specify a custom separater for the last two elements.

This template:

<pre ng-init="x = ['parsley', 'sage', 'rosemary', 'thyme']">
{{ x | join : ', ' }}
{{ x | join : ', ' : ' and ' }}
</pre>

would produce the following output:

parsley, sage, rosemary, thyme
parsley, sage, rosemary and thyme

If you're interested, I can make that change and send you a PR.

frapontillo commented 10 years ago

join is thought to provide a filter interface for the Array.prototype.join method, so I wouldn't go with that. You can instead use a custom function on your $scope or a custom filter.