2017-06-29 72 views
0

我有3個角度功能,切換搜索功能。但是,我只希望能夠一次選擇一個。禁用按鈕,而另一個選擇使用角度

/* Trauma Search functionality */ 
 
$scope.traumaSearch = false; 
 
$scope.traumaText = "Trauma Center"; 
 
$scope.toggleTraumaSearch = function() { 
 
    $scope.traumaSearch = !$scope.traumaSearch; 
 
    if ($scope.traumaSearch) { 
 
    $scope.traumaText = "Select a location..."; 
 
    canvas.style.cursor = 'crosshair'; 
 
    } else { 
 
    $scope.traumaText = "Trauma Center"; 
 
    canvas.style.cursor = ''; 
 
    } 
 
} 
 

 
/* Police Search functionality */ 
 
$scope.policeSearch = false; 
 
$scope.policeText = "Police Station"; 
 
$scope.togglePoliceSearch = function() { 
 
    $scope.policeSearch = !$scope.policeSearch; 
 
    if ($scope.policeSearch) { 
 
    $scope.policeText = "Select a location..."; 
 
    canvas.style.cursor = 'crosshair'; 
 
    } else { 
 
    $scope.policeText = "Police Station"; 
 
    canvas.style.cursor = ''; 
 
    } 
 
} 
 

 
/* Fire Search functionality */ 
 
$scope.fireSearch = false; 
 
$scope.fireText = "Fire Station"; 
 
$scope.toggleFireSearch = function() { 
 
    $scope.fireSearch = !$scope.fireSearch; 
 
    if ($scope.fireSearch) { 
 
    $scope.fireText = "Select a location..."; 
 
    canvas.style.cursor = 'crosshair'; 
 
    } else { 
 
    $scope.fireText = "Fire Station"; 
 
    canvas.style.cursor = ''; 
 
    } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div id="marker"> 
 
    <!-- LOCATION BUTTONS --> 
 
    <h2>Find the Nearest Emergency Services</h2> 
 
    <button class="btn btn-info" ng-click="toggleTraumaSearch()">{{traumaText}} </button> 
 
    <button class="btn btn-info" ng-click="togglePoliceSearch()">{{policeText}}</button> 
 
    <button class="btn btn-info" ng-click="toggleFireSearch()">{{fireText}}</button> 
 
</div>

我嘗試用NG-殘疾人解決這個(這裏disable the button after one click using ng-disable解釋),但沒有奏效。尤其是第二種解決方案,通過添加第二個「if」語句,該功能被打破了。這可能是由於我使用不正確的語法。

我也嘗試限制用戶的輸入作爲功能範圍的一部分。它可能是一個新用戶,我通過添加「$ scope.toggleFireSearch.input = false」來使用不正確的語法。

也許我在吠叫錯誤的樹。任何建議指導解決我的問題的建議?

回答

0

您可以使用元素標記ng-if="VARNAME"來檢查您的範圍內的變量是否爲真。對每個搜索元素(或數組)有不同的變量。然後,你可以讓ToggleWhateverSearch()將該var設置爲true,其他所有其他設置爲false。

相關問題