我想编写一个指令,在http请求期间保持按钮和页面禁用。如何禁用按钮,直到在AngularJS中处理/加载http请求?
如果我更新或提交表单,该按钮将禁用,直到HTTP响应 完成。
加载页面时,它将禁用,直到从服务器加载的整个数据为 。
10秒后,该按钮将处于活动状态,用户可以多次点击 。
app.js
<script>
var angModule = angular.module("myApp", []);
angModule.controller("myCtrl", function ($scope, $timeout) {
$scope.isSaving = undefined;
$scope.btnVal = 'Yes';
$scope.save = function()
{
$scope.isSaving = true;
$timeout(function()
{
$scope.isSaving = false;
}, 1000);
};
});
</script>
的index.html
<div ng-app="myApp">
<ng-form ng-controller="myCtrl">
Saving: {{isSaving}}
<button ng-click="save()" ng-disabled="isSaving">
<span ng-hide="isSaving">Save</span>
<span ng-show="isSaving">Loading...</span><i class="fa fa-spinner fa-spin" ng-show="isSaving"></i>
</button>
</ng-form>
</div>
我是新来AngularJS,请帮我写了这样的指令。
你可以找到如何创建自定义指令非常有用的信息[这里](https://docs.angularjs.org/guide/directive) – Filipe