1

How can I add the selected item from dropdown menu to the button that opens that dropdown?

Example: I want to replace 'DIFFERENCES' with text selected from the dropdown menu; if I select 'All' then the text 'DIFFERENCES' should be replaced with 'All'...

<div class="filter-requests btn-group">
  <div data-toggle="dropdown">
    <a href="#" class="btn btn-default dropdown-toggle">
      DIFFERENCES
      <i class="fa fa-chevron-down"></i>
    </a>
  </div>
  <ul class="dropdown-menu">
    <li><a href="#">All</a></li>
    <li><a href="#" >Exclusions</a></li>
    <li><a href="#" >Differences</a></li>
    <li><a href="#" >Variable Differences</a></li>
    <li><a href="#" >Path Differences</a></li>
  </ul>
</div>
0

2 Answers 2

2

view.html

<div class="btn-group" uib-dropdown is-open="status.isopen">
  <button id="single-button" type="button" class="btn btn-primary" uib-dropdown-toggle>
    {{selected || 'Select one'}} <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="single-button">
    <li role="menuitem"><a href="#" ng-click="changeOption('Action')">Action</a></li>
    <li role="menuitem"><a href="#" ng-click="changeOption('Another action')">Another action</a></li>
    <li role="menuitem"><a href="#" ng-click="changeOption('Something else here')">Something else here</a></li>
    <li class="divider"></li>
    <li role="menuitem"><a href="#" ng-click="changeOption('Separated link')">Separated link</a></li>
  </ul>
</div>

controller.js

  $scope.selected = null;
  $scope.changeOption = function(text) {
    $scope.selected = text;
  }
Sign up to request clarification or add additional context in comments.

Comments

1

try like this.

var app = angular.module("app",[]);

app.controller("ctrl" , function($scope){
  $scope.row = "";
  $scope.items = ['All','Exclusions','Differences','Variable Differences'];
 
  $scope.selectRow = function(item){
      $scope.row = item;
    }
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
  <div ng-app="app" ng-controller="ctrl" class="filter-requests btn-group">
    <div data-toggle="dropdown">
    <a href="#" class="btn btn-default dropdown-toggle">
      {{row}}
      <i class="fa fa-chevron-down"></i>
    </a>
  </div>
    <ul class="dropdown-menu" >
       <li ng-repeat="item in items"  ng-click="selectRow(item)">
           <a href="">{{item}}</a>
        </li>              
     </ul>        
</div>

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.