2016-08-24 87 views
2
<div class="container" ng-controller="serviceHistoryController"> 
    <!-- Search box Start --> 
    <div class="dropdown col-xs-8"> 
      <button class="btn btn-default col-xs-4" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="false" aria-expanded="true"> 
      Select SUT 
      <span class="caret"></span> 
      </button> 
      <ul class="dropdown-menu col-xs-8" aria-labelledby="dropdownMenu1"> 
      <li ng-repeat="sutname in sutlist"> 
        <a href="#" ng-click="sutselected(sutname)"> 
         {{sutname.name}} 
        </a> 
      </li> 
      </ul> 
    </div> 
</div> 

上面是我使用的引導+角度下拉代碼。但是,一旦我點擊下拉菜單,它就會消失。我正在使用angular1 + boostrap 3.3.7和jquery 1.12.4庫。沒有使用其他腳本或js。點擊後引導下拉消失

以下是角功能

app.controller("serviceHistoryController",function($scope){  
    let menuitems = [{"sutid":"1","name":"AA"}, 
        {"sutid":"2","name":"BB"}, 
        {"sutid":"3","name":"CC"}, 
        {"sutid":"4","name":"DD"}, 
        {"sutid":"4","name":"EE"}] 
    $scope.sutlist = menuitems; 
    $scope.selectedSUT; 

    $scope.sutselected = function(sutname){ 
     $scope.selectedSUT = sutname; 
     alert("dropdown sut selected:"+$scope.selectedSUT.name); 
    } 
}); 
+0

有一個在你的代碼一個錯字=>'詠歎調-haspopup = 「FLASE」'。它需要'假'不''flase' –

+0

暴露您的sutselected角功能 – Aravind

+0

@Aravind請檢查更新的問題 – vashishth

回答

0

的問題是與您的數據類型使用VAR看到修改後的控制器。

app.controller("serviceHistoryController",function($scope){  
    var menuitems = [{"sutid":"1","name":"AA"}, 
        {"sutid":"2","name":"BB"}, 
        {"sutid":"3","name":"CC"}, 
        {"sutid":"4","name":"DD"}, 
        {"sutid":"4","name":"EE"}] 
    $scope.sutlist = menuitems; 
    $scope.selectedSUT; 

    $scope.sutselected = function(sutname){ 
     $scope.selectedSUT = sutname; 
     alert("dropdown sut selected:"+$scope.selectedSUT.name); 
    } 
}); 
+0

我有上面的測試,沒有運氣。讓let是es6的有效數據類型。 – vashishth

0

請參見

var app = angular.module('main', []); 
 
app.controller("serviceHistoryController",function($scope){  
 
    var menuitems = [{"sutid":"1","name":"AA"}, 
 
        {"sutid":"2","name":"BB"}, 
 
        {"sutid":"3","name":"CC"}, 
 
        {"sutid":"4","name":"DD"}, 
 
        {"sutid":"4","name":"EE"}] 
 
    $scope.sutlist = menuitems; 
 
    $scope.selectedSUT; 
 

 
    $scope.sutselected = function(sutname){ 
 
     $scope.selectedSUT = sutname; 
 
     alert("dropdown sut selected:"+$scope.selectedSUT.name); 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 

 
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" > 
 
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" ></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 

 
<div ng-app="main" class="container" ng-controller="serviceHistoryController"> 
 
    Normal : <select> 
 
     <option>select</option> 
 
    <option ng-repeat="sutname in sutlist"> {{sutname.name}}</option> 
 
    </select> 
 
    <br/> <br/> 
 
    <!-- Search box Start --> 
 
    <div class="dropdown col-xs-8"> 
 
     Bootstrap <button class="btn btn-default col-xs-4" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="flase" aria-expanded="true"> 
 
      Click Here 
 
      <span class="caret"></span> 
 
      </button> 
 
      <ul class="dropdown-menu col-xs-8" aria-labelledby="dropdownMenu1"> 
 
      <li ng-repeat="sutname in sutlist"> 
 
        <a href="#" ng-click="sutselected(sutname)"> 
 
         {{sutname.name}} 
 
        </a> 
 
      </li> 
 
      </ul> 
 
     
 
     
 
    </div> 
 
</div>

+0

它正常工作和bootstrap什麼問題? – Pravin

+0

在bootstrap下拉菜單中,像按鈕一樣,請參閱http://getbootstrap.com/components/#dropdowns – Pravin

+0

:(奇怪的是,我不明白它爲什麼不能與我合作,這是應用程序模塊,我是usign - 讓mockapp = angular .module(「mockapp」,['ngSanitize','ngRoute','ngMessages','ctrlModule']);,現在我正在嘗試使用ui-bootstrap – vashishth