为什么ng-disabled不起作用?

时间:2017-11-24 13:54:24

标签: javascript angularjs

我尝试禁用带有ng-disabled的<a>但不能正常工作,我将其设置为禁用,但它也不起作用。我的HTML就像这样

<div class="action-engine">
    <a on-hold="engine()" class="btn3d default actived" ng-disabled="button_clicked">
        <div class="back-overlay"></div>
        <div class="inner-circle">
             <div class="inner-icon"></div>
        </div>
    </a>
</div>

我在JS中加入了 $scope.button_clicked = true; 。我不知道它还能按。如果您有一些想法来解决我的问题,那就很有帮助。感谢

2 个答案:

答案 0 :(得分:0)

按钮应该用于禁用ng: -

&#13;
&#13;
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {

$scope.button_clicked = true;
});
&#13;
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

<body>

  <div ng-app="myApp" ng-controller="myCtrl">

    <div class="action-engine">
      <button on-hold="engine()" class="btn3d default actived" ng-disabled="button_clicked">
        <div class="back-overlay"></div>
        <div class="inner-circle">
             <div class="inner-icon">Link</div>
        </div>
      </button>
    </div>
  </div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

<div class="action-engine">
    <a on-hold="engine()" class="btn3d default actived" ng-disabled="button_clicked">
        <div class="back-overlay"></div>
        <div class="inner-circle">
             <div class="inner-icon"></div>
        </div>
    </a>
</div>

html中的a标签不会被禁用。 使用

在课堂下面使用
ng-class="{'avoid-clicks' : button_clicked }"

.avoid-clicks {
    pointer-events: none;
}