angularjs中的ng-disabled对我不起作用

时间:2014-04-21 11:49:31

标签: angularjs angularjs-directive angularjs-scope angular-ui

我正在尝试使用某些条件启用和禁用按钮

我可以使用$scope.isDisabled = true;禁用按钮,但无法启用按钮

这是我的代码

HTML文件

<input type="submit" value="Continue" ng-model="isDisabled" ng-disabled="isDisabled">

控制器JS文件

$scope.isDisabled = true; // here the button disabled (for me)

if (count >= 3) {       // it's always true          
      $scope.isDisabled = false;   // try to enable the button here
}

1 个答案:

答案 0 :(得分:1)

  1. 不要使用$ scope.apply。这不是它的意思。
  2. 该按钮不需要绑定到模型,尝试从按钮中删除ng-model。
  3. 另外,如果它是“提交”的输入类型而您不在ng-form中,那可能就是这样 导致回发,你可能会失去你的状态。
  4. 这是一个显示它正常工作的插件 - 我做了一些假设以使得插件正常运行。添加了一个触发计数增量的额外按钮。

    http://plnkr.co/edit/QGYMqGHCKUoDGaY9WYhj?p=preview