1
我創造了這個提醒服務:如何使用AngularJS服務複製Javascript確認功能?
class AlertService {
msg = null;
constructor() { }
confirm = (msg) => {
var self = this
this.msg = msg;
}
cancel =() => {
this.msg = null;
return false;
}
okay =() => {
this.msg = null;
return true;
}
}
我想這樣做是爲了在我的控制器是這樣的:
alertService.Confirm("Confirm or cancel")
.then(function() {
ts.doDelete(es.exam.examId)
}
這裏是我的HTML。請注意,al已連線至AlertService。
<div id="alert"
ng-show="al.msg">
<div>{{ al.msg }}</div>
<button ng-click="al.okay()">
Okay
</button>
<button ng-click="al.cancel()">
Cancel
</button>
</div>
我這個問題是我知道如何調用確認(),並將它傳遞的消息,但我怎樣才能使報警服務坐下等待,直到用戶按下取消或以類似的方式來好吧按鈕當我使用javascript確認在屏幕上顯示確認框時?