0

I've implemented a drop down list on a project I'm working on using AngularJS.

The HTML snippet is as follows:

<input-multiselect [list]="transactionState" placeholder="Choose Your Transaction State">
<ng-container class="c-legend">Transaction status</ng-container>
</input-multiselect> 

I'm using an array and a switch case to store the values that are needed in the drop down for a few different cases.

The JS code is below:

export class SearchPageComponent implements OnInit {
    transactionState: Array<any>;
    setTransactionDropdown() {
        switch (this.userGroup) {
            case 5:
               this.transactionState = [
                  { value: 'READY_INV', label: 'Ready for Invites' },
                  { value: 'NOT_READY_INV', label: 'Not Ready for Invites' },
               ];
               break;
          }
     }

What I want to do is have a function that can access this.transactionState and get the values that have been selected, so that I can pass these values on to another function.

Can anyone help me with this please? Is there a better method I could have used?

Thanks in advance!

Barr J
  • 10,636
  • 1
  • 28
  • 46

1 Answers1

0

The solution I found, was to add a function call to the end of every case, have a flag to let me know what's been checked. The flag is value: true Please find a code snippet below:

case 1:
        this.transactionState = [
          { value: true , code: 'INV_SENT', label: 'Invites Sent' },
        this.getTransactionStateInfo();

The function itself loops through the object called this.transactionState, and gets the values that are flagged true and pushes them to another array that I can use for other things.

getTransactionStateInfo() {
    const transactionStateObj: any = [];
    this.transactionState.forEach((i) => {
      if (i.value === true) {
        console.log(i.code);
        transactionStateObj.push(i.code);
      }
    });
 }