Home How to properly set selected <li> using Angular-UI Dropdown
Reply: 0

How to properly set selected <li> using Angular-UI Dropdown

user1223
1#
user1223 Published in April 26, 2018, 1:42 pm

I have a dropdown control, implemented as follows:

<div uib-dropdown="dropdown" class="btn-group">
     <button uib-dropdown-toggle="" class="btn btn-default">Open With <b class="caret"></b>
     </button>
     <ul role="menu" class="dropdown-menu animated fadeIn">
       <li ng-repeat="list in templateList" ng-click="setValue(list)" data-ng-model="selectedOption"
       >{{list.name}}</li>
     </ul>
</div>

The corresponding Angular controller code looks like this:

    $scope.templateList = [{id:1, name: 'H2O'}, {id:2, name: 'R'}, {id: 3, name: "Python"}];

    $scope.selectedOption = $scope.templateList[1];

    $scope.template = {};
    $scope.setValue = function(list) {
        $scope.template.template_id = list.id;
        $scope.template.template_name = list.name;
        console.log("selected item:  " + list.name);
    };

Once a particular item from the dropdown has been selected, I need the dropdown to show the selection in place of default "Open With" option.

What code charge do I need to make to programmatically control the dropdown selection?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.460188 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO