Angular js ng-dissabled不起作用

时间:2015-07-10 08:10:06

标签: javascript jquery angularjs

我的HTML ............................................. ..............................

 <div id="ButtonController" ng-app="buttons" ng-controller="ButtonController   as controller">

            @*<span ng-disabled="controller.access.canClose">@Html.Kendo().Button().Name("tabDelete").Content("Close").Icon("cancel")</span>
            <span ng-disabled="controller.access.canEdit">@Html.Kendo().Button().Name("Edit").Content("Edit")</span>*@
        <button ng-disabled="controller.access.canClose" class="k-button k-button-icontext" title="Close Tab" type="button" id="tabDelete" >Close</button>
        <button ng-disabled="controller.access.canEdit" class="k-button k-button-icontext" title="Edit" type="button" id="Edit" >Edit</button>
        <button id="save" class="k-button k-button-icontext" >Save</button>

    </div>

我的js

  (function () {
var app = angular.module('buttons', []);

app.controller('ButtonController', function ($scope, $http) {
    $scope.myfunctions = function (obj) {
        if (obj != "Stop") {
            $http.get("/home/setButtonRights?tr_code=" + obj)
                   .success(function (response) {
                       buttonVisibility.canClose = response.canClose;
                       buttonVisibility.canEdit = response.canEdit;
                   })
                       .error(function () { alert("Done") });
        } else {
            buttonVisibility.canClose = true;
            buttonVisibility.canEdit = true;


        }
    }

        this.access = buttonVisibility;

});
}
var buttonVisibility = {
    canEdit: true,
    canClose:true
}

})();

当我通过“停止”此控制器按钮仍然有效。我想在停止obj时禁用这些按钮。

2 个答案:

答案 0 :(得分:1)

为什么你试图实现有点奇怪。 您想在disabled上设置属性<span> ...但为什么? <span>不是表单元素。浏览器不会在非表单元素上尊重此属性。

您应该使用<button>或ng-class,例如ng-class={'disabled':'some-bool-criteria'}

答案 1 :(得分:0)

您的代码中有一个额外的大括号。否则它应该工作正常。这是更新的:

(function () {
var app = angular.module('buttons', []);

app.controller('ButtonController', function ($scope, $http) {
    $scope.myfunctions = function (obj) {
        if (obj != "Stop") {
            $http.get("/home/setButtonRights?tr_code=" + obj)
                   .success(function (response) {
                       buttonVisibility.canClose = response.canClose;
                       buttonVisibility.canEdit = response.canEdit;
                   })
                       .error(function () { alert("Done") });
        } else {
            buttonVisibility.canClose = true;
            buttonVisibility.canEdit = true;


        }
    }

        this.access = buttonVisibility;

});

var buttonVisibility = {
    canEdit: true,
    canClose:true
}

})();