2015-07-10 114 views
0

我的HTML ...................................... .....................................角度js ng-dissabled不起作用

<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 
} 

})(); 

當我通過「停止」這個控制器按鈕仍然活躍。我想在stop obj到來時禁用這些按鈕。

+0

你所說的'的意思,當我通過「停止」這一controller' –

+0

您是否獲得在控制檯中的任何錯誤? – Tushar

+0

在ng-disabled或(更好)使用ng-enabled中反轉表達式。 – ChristophT

回答

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 
} 

})(); 
1

爲什麼你試圖實現有點奇怪。 你想在<span>上設置屬性disabled ...但是爲什麼? <span>不是表單元素。瀏覽器不會尊重非表單元素上的此屬性。

您應該使用<button>或納克級這樣ng-class={'disabled':'some-bool-criteria'}