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>
想知道这是否是做的正确的方式。 我想避免使用$手表
谢谢。