0
我有下面的代碼,我已經嘗試了所有事情,以返回一個承諾,將與該指令一起工作。我甚至嘗試過返回響應數據並返回$ q.when(數據)並且什麼也沒有。我試着讀過諾言,這篇文章有點不同,然後我讀了。我失蹤的東西?如何回覆承諾以滿足指令?
myApp.controller('smsCtrl', function($scope){
$scope.sendSMS = function(){
let sms = {'number': $scope.number ,'message': $scope.message};
serviceNameHere.sendSMS(sms).then(function(response){
$scope.smsSuccessMsg = "Message Sent Successfully";
}, function(response){
$scope.smsErrorMsg = response.data['message'];
});
};
})
myApp.directive('onClickDisable', function() {
return {
scope: {
onClickDisable: '&'
},
link: function(scope, element, attrs) {
element.bind('click', function() {
element.prop('disabled',true);
scope.onClickDisable().finally(function() {
element.prop('disabled',false);
})
});
}
};
});
以下HTML
<div ng-controller="smsCtrl">
<-- field inputs here --></-->
<button type="button" class="btn btn-primary" on-click-disable="sendSMS()">SEND</button>
</div>
你的小提琴不可用,還有,你想做什麼?請求完成後再重新啓用它? – Icepickle
'返回承諾' - 提示:如果你想要一個函數返回任何東西(甚至是承諾),你需要一個'返回'某處 –
一旦你修復了小提琴鏈接,你也可以刪除它... * ReferenceError:角度沒有定義* - 沒有意義的小提琴失敗的基礎知識 –