5
我寫了一個指令,可以在ajax請求未決時幫助禁用按鈕。ajax請求時禁用按鈕
這是我的指令:
.directive('requestPending', ['$http', function ($http) {
return {
restrict: 'A',
scope: {
'requestPending': '='
},
link: function (scope, el, attr) {
scope.$watch(function() {
return $http.pendingRequests.length;
}, function (requests) {
scope.requestPending = requests > 0;
})
}
}
}])
的HTML是這樣的:
<button request-pending="pending" ng-disabled="pending">Save</button>
想知道這是否是做的正確的方式。 我想避免使用$手錶
謝謝。