Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning ng-model for dropdown

I have a item in list with with dropdown values as ROLES. I couldn't set ng-model for drop down .if I select Actor I wanted my ng-model to be set as Actor

<li class="dropdown" ng-model="$scope.Role">
          <a class="dropdown-toggle" data-toggle="dropdown">VIEW ROLE AS
 <span class="caret"></span></a>
          <ul class="dropdown-menu">
           <li>Actor</li>
          <li>Director</li>
   </li>
like image 483
Nicoleta Wilskon Avatar asked Jun 13 '26 08:06

Nicoleta Wilskon


1 Answers

'ng-model' only works on inputs and since the bootstrap dropdown is just a stylized list it has no real input. To get your example to work use 'ng-click' on the list elements to set 'Role'.

<li class="dropdown">
      <a class="dropdown-toggle" data-toggle="dropdown">VIEW ROLE AS
<span class="caret"></span></a>
      <ul class="dropdown-menu">
       <li ng-click="setRole('Actor')">Actor</li>
      <li ng-click="setRole('Director')">Director</li>

And then somewhere in the controller create the 'setRole' function.

$scope.setRole = function (role) {
    $scope.Role = role;
}
like image 104
Umer Z Avatar answered Jun 15 '26 00:06

Umer Z



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!