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」來使用不正確的語法。
也許我在吠叫錯誤的樹。任何建議指導解決我的問題的建議?