0

I want to display dropdown options depending on the value I pass in controller

Controller:

This.selectedColumn = label;

This.dditems = [
    {
        id: 1,
        label: 'aLabel',
        subItem: 'aSubItem'
    },
    {
        id: 2,
        label: 'bLabel',
        subItem: 'bSubItem'
    },
    {
        id: 3,
        label: 'bLabel',
        subItem: 'cSubItem'
    }
];

In above code I have selectedColumn as label, then I should display dditems.label in dropdown. If I pass selectedColumn as subItem, then I should display dditems.subItem in dropdown.

Html:

<ul class="dropdown-menu" role="menu" aria-labelledby="single-button" >
    <li role="menuitem" data-ng-repeat="item in dc.dditems">
       <a>{{ item.label }}</a>
   </li>
</ul>

In above code I have hardcoded item.label, so now item.label column is displaying. But I want to display value based on selectedColumn.

Eg: <a>{{ item.selectedColumn }}</a>

How can I do this dynamic way?

1 Answer 1

1

I've have a made a Fiddle for your solution. You can change the click event with any event you want your repeat property to change.

According to your code you just have to change the selectedColumn variable with any event.

<ul class="dropdown-menu" role="menu" aria-labelledby="single-button" >
    <li role="menuitem" data-ng-repeat="item in dc.dditems">
       <a>{{ item[selectedColumn] }}</a>
   </li>
</ul>

Hope it helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.