2
我有一個引導警報,看起來像這樣NG-點擊按鈕
<div id="errorAlert" class="alert col-md-6 col-md-offset-3 fadeAlert" ng-if="itemExistsAlert">
<button type="button" class="close" data-dismiss="alert">×</button>
<p>{{alertMessage}}</p>
</div>
,我會添加/動態使用jQuery /角(代碼刪除類的第二次點擊只會火下面,當用戶不將任何值輸入文本,並單擊addItem
按鈕)將只運行
的addItem按鈕:
<button ng-click="addItem()" class="btn btn-success" type="button">Add</button>
功能,將手樂納克單擊
$scope.addItem = function() {
var errorAlert = angular.element(document.querySelector('#errorAlert'));
if (!$scope.pollItem) {
errorAlert.addClass('alert-info');
$scope.alertMessage = "Item cannot be null";
$scope.itemExistsAlert = true;
$timeout(function() {
$scope.itemExistsAlert = false;
}, 2000)
return;
}
}
的代碼運行良好但的addClass
事件只會發生火災後,我會按一下按鈕兩次。我的意思是警報將會完全淡入/淡入淡出,但只有第一次點擊纔會添加該類,而第二次點擊按鈕時該類將被添加到警報中。
謝謝任何能夠幫助我的人。
順便說一句,我使用的角度v1.6.4它是否會有所幫助。謝謝! –