Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度-范围更改后禁用ng不工作_Javascript_Angularjs - Fatal编程技术网

Javascript 角度-范围更改后禁用ng不工作

Javascript 角度-范围更改后禁用ng不工作,javascript,angularjs,Javascript,Angularjs,我有一个输入和一个按钮。我希望在输入为空或长度超过15个字符时禁用该按钮 HTML <input type="text" id="addCustomer" ng-model="customerNumber"> <button id="addSingleCustomerButton" ng-disabled="!isValidSingleInput(customerNumber)" ng-click="addCustomer()"></button> 在add

我有一个输入和一个按钮。我希望在输入为空或长度超过15个字符时禁用该按钮

HTML

<input type="text" id="addCustomer" ng-model="customerNumber">
<button id="addSingleCustomerButton" ng-disabled="!isValidSingleInput(customerNumber)" ng-click="addCustomer()"></button>
addCustomer
函数的末尾,通过将作用域设置为
$scope.customerNumber=''来清除输入字段

但是,清除输入后,按钮不会再次禁用。我在
isValidInput
函数中添加了一个日志,其中包含它的结果,在清除输入后,它返回
false
。因此调用该函数并返回预期值,但不知何故,它对按钮的
ng disabled
没有影响

编辑:添加功能
addCustomer


EDIT2:认为这无关紧要,但问题是由Bootstrap的button.js引起的。如果我移除
.button('loading')
.button('reset')
它正在工作。在我看来,这无论如何都应该有效,因为我正在重置按钮后的范围。

你能检查一下为什么它可能不适用于你吗

var-app=angular.module('myApp',[]);
应用程序控制器('myCtrl',函数($scope){
$scope.firstName=“John”;
$scope.lastName=“Doe”;
$scope.isValidSingleInput=函数(输入){

return(input!=undefined&&input.length>0&&input.length显示更多代码…因为我复制了您的代码并在这里尝试了它的工作状态很好!编辑了我的问题您可以尝试此-->?是的,我当然可以实现
.button()
手动功能,但我认为它应该按原样工作……我的情况不同之处在于,我有一个异步调用来将客户号码保存在数据库中。然后在回调中清除输入。
$scope.isValidSingleInput = function(input) {
    return (input != undefined && input.length > 0 && input.length <= 15);
}
$scope.addCustomer = function() {
    $('#addSingleCustomerButton').button('loading');

    // Call service to add customer number to database
    CustomerService.add({}, payload, function(data) {
        $('#addSingleCustomerButton').button('reset');
        $scope.customerNumber = '';
    });
}