angularjs - Use filter on ng-options to change the value displayed -


i have array of prices (0, 0.99, 1.99... etc) want display in <select>.

i want use angular's ng-options

<select ng-model="create_price" ng-options="obj obj in prices"/> 

as displayed above generate selection of 0, 0.99, 1.99...

but want use filter in code such every time word 'prices' presented (or that), code run function change float numbers strings , present (free, 0.99$, 1.99$... etc).

i there way that?

thanks

there's better way:

app.filter('price', function() {   return function(num) {     return num === 0 ? 'free' : num + '$';   }; }); 

then use this:

<select ng-model="create_price" ng-options="obj (obj | price) obj in prices"> </select> 

this way, filter useful single values, rather operating on arrays. if have objects , corresponding formatting filters, quite useful.

filters can used directly in code, if need them:

var formattedprice = $filter('price')(num); 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -