I'm still new to Angular/JS... I'm displaying a bunch of data through filter pipe, and I now want the ability to toggle how my data is ordered: ascending or descending. I have an "orderBy" pipe that is working perfectly, but I currently have to hardcode the direction, and I want it to be dynamic. I want to achieve this via two radio buttons, but I'm having trouble grabbing the input value and inserting it into my *ngFor directive.
<input type="radio" value="+"> Ascending<br>
<input type="radio" value="-"> Descending<br>
I need to grab the "+" or "-" and insert it just before the "recordStartDate."
<li (click)="showArtist(item);"
*ngFor="let item of artists | search: field1Filter | orderBy:
['recordStartDate']">
</li>
['-recordStartDate'] results in descending order, and ['+recordStartDate'] (or no sign at all) produces ascending.
What is the best way to achieve this?
Thank you!
Edit:
I'm using this pipe here: https://stackoverflow.com/a/35635370/8201772 and there's a demo of it here: http://fuelinteractive.github.io/fuel-ui/#/pipe/orderby. Notice that on the demo there're select options which control whether the data is sorted in ascending or descending order via "+" and "-". How can I replicate these select option functionality? I'd comment on the original answer, but I need 50+ reputation to do so. Thanks!
Edit two:
Okay, so I've updated the two radio-buttons as seen below:
<input type="radio" name="orderbydescending" [(ngModel)]="orderbydescending" value="['+recordStartDate']">Ascending<br>
<input type="radio" name="orderbydescending" [(ngModel)]="orderbydescending" value="['-recordStartDate']">Descending
and use the following in my view:
*ngFor="let item of artists | search: field1Filter | orderBy : orderbydescending"
then I get the following error: https://i.stack.imgur.com/Himx7.jpg.
If I remove the " [' " and " '] " the values of the radio buttons then the pipe stops working correctly (and I still get the same error).
Any ideas? Again, hardcoding this works perfectly. Thanks!