javascript - AngularJS - Filter list by object property that has filter applied to it -
i want filter list of objects properties , used filter
filter. problem object properties have filters applied them change format in displayed (see formatdate filter in code below) , filter
filter use unformatted object properties.
e.g.: there video .duration = 150 (seconds) displayed 00:02:30 (because of formatdate filter). if user searches "02", video not found because .duration property of video searched , "02" doesn't match 150.
what easiest way filter displayed value instead of "raw" value?
thought adding getdurationformatted() function every object in list , displaying , filtering property, severely decrease expressiveness of html.
<input ng-model="query"> <tr ng-repeat="video in videos | filter:query"> <td> {{ video.name }} </td> <td> <!-- formatdate filter used format amount of seconds --> {{ video.duration | formatdate:'hh:mm:ss' }} </td> </td>
you can extend every object in array additional preformatted property corresponding users see. filtering work user friendly input.
this simplest solution requires minor template modification:
<tr ng-repeat="video in videos | filter:query"> <td> {{ video.name }} </td> <td> <!-- formatdate filter used format amount of seconds --> {{ video.durationformatted = (video.duration | formatdate:'hh:mm:ss') }} </td> </tr>
Comments
Post a Comment