Javascript AngularJS提交时禁用按钮-错误时重新启用
动态禁用按钮时出现问题 我的API休眠2秒以模拟超慢速连接,我希望看到submit按钮在submit时被禁用,而re-enable本身被禁用 HTML-手动禁用按钮可以工作Javascript AngularJS提交时禁用按钮-错误时重新启用,javascript,html,ajax,angularjs,Javascript,Html,Ajax,Angularjs,动态禁用按钮时出现问题 我的API休眠2秒以模拟超慢速连接,我希望看到submit按钮在submit时被禁用,而re-enable本身被禁用 HTML-手动禁用按钮可以工作 <button data-ng-disabled="false" data-ng-click="submit()">Schedule Appointment</button> 一切工作正常,console.log输出正确保存。问题是,除非我将ng disabled=true硬编码到html中,否则按
<button data-ng-disabled="false" data-ng-click="submit()">Schedule Appointment</button>
一切工作正常,console.log输出正确保存。问题是,除非我将ng disabled=true硬编码到html中,否则按钮实际上不会被禁用。问题在于html。 在ng指令中访问范围变量时,不需要{{}
<button ng-disabled="isSaving" ng-click="submit()">Schedule Appointment</button>
希望有帮助。尝试用禁用数据ng替换禁用数据ng={{isSaving}}}=isSaving@BogdanSavluk-那很容易啊!!!它是有效的。。。非常感谢你!我如何知道何时需要使用{{}以及何时不使用它?这取决于所需的参数类型,在禁用ng的情况下,将在作用域上计算表达式。例如,指令ng href需要使用作用域插入的模板。在本例中,参数可以是任何字符串,可能带有{{}
app.controller('ScheduleController', function ($scope, $http, $window, $timeout)
{
$scope.formData = {};
$scope.isSaving = false;
$scope.submit = function() {
$scope.isSaving = true;
console.log('Schedule Appointment Pressed, isSaving', $scope.isSaving);
$http.post('/api/v1/schedule/', $scope.formData)
.success(function(data) {
// Do Stuff
})
.error(function(data){
$scope.isSaving = false;
console.log('Error, isSaving', $scope.isSaving);
$scope.errors = data.errors;
});
}
});
<button ng-disabled="isSaving" ng-click="submit()">Schedule Appointment</button>