1

分配我有一个复选框,以显示停用的帐户,当请求被选中的复选框我需要发送activationstatus虚假用于显示禁用帐户,未选中时,它应该通过价值为真。我的复选框只是在初始化$ scope.checkedStatus = true之后传递相同的值。值不会传递为false。值不会自动在复选框

HTML:

<div> 
<input type="checkbox" ng-model="checkedStatus" ng-click = "viewAccount"> 
    Show Deactivated Account 
</div> 

JS:

$scope.checkedStatus = true; 
$scope.viewAccount = function(){ 

       var json = { 
    "json": { 
    "request": { 
     "servicetype": "6", 
     "functiontype": "6014", 
     "session_id": $rootScope.currentSession, 
      "data": { 
     "shortname": $scope.model.selectShortName, 
     "groupzname": $scope.model.selectGname, 
     "city": $scope.model.selectCity, 
     "state": $scope.model.selectState, 
     "country": $scope.model.selectCountry, 
     "groupzcode": $scope.model.selectGcode, 
     "activationstatus": !($scope.checkedStatus), 
     "details": false, 
     "sortbasedon": $scope.groupzname, 
     "orderby": "desc", 
     "offset":$scope.pagination 
      } 

    } 
    } 
}; 

    UserService.viewListAccount(json).then(function(response) { 
    if (response.json.response.statuscode == 0) 
         { 
        $scope.tableData = response.json.response.data; 
         } 
       }); 
     }; 

自动复选框是不会改变的价值。

回答

0

在你的JSON你只是否定$scope.checkedStatus但不改变其值。所以你总是得到相同的结果。
而不是在你的JSON使用!($scope.checkedStatus)的,你可以改变范围值。

$scope.checkedStatus = true; 
$scope.viewAccount = function(){ 
    $scope.checkedStatus = !$scope.checkedStatus; //check this line 
    var json = { 
    "json": { 
     "request": { 
     "servicetype": "6", 
     "functiontype": "6014", 
      . 
      . 
      "activationstatus": $scope.checkedStatus, 
      . 
      . 
      "orderby": "desc", 
      "offset":$scope.pagination 
      } 

     } 
    } 
}; 
0

您可以输入使用

NG-变化

。 在这里你可以在html中完成。

<input type="checkbox" ng-model="checkedStatus" ng-click = "viewAccount" ng-change="change()"> 
    Show Deactivated Account 
</div> 

您将如何在控制器中访问它。

$scope.change = function() { 
    $scope.viewAccount(); 
} 
+0

这会带来什么变化,反正它指的是相同的功能仪式? –

+0

是的。你可以安慰checkedStatus的输出在功能 –

+0

这里是样品(的jsfiddle)http://jsfiddle.net/cLenjedL/7/ –

0

创建一个包装对象,在$范围模式并在其中创建checkedStatus财产。

$scope.model = { 
    checkedStatus: true 
}; 

并在其引用的地方进行相关更改。

HTML类似,这些更改

ng-click="viewAccount()" ng-model="model.checkedStatus" 

另外,作为一个侧面说明,你不应该直接连上作用域属性,总是尝试创建一个包装对象或使用控制器的语法来摆脱这种的问题。

看看这篇文章:AngularJS: If you don't have a dot, you're doing it wrong - See more at: http://zcourts.com/2013/05/31/angularjs-if-you-dont-have-a-dot-youre-doing-it-wrong/#sthash.NDNvWL5E.dpuf

0

对于复选框角已经特殊指令称为ng-change使用,来代替。

<div> 
    <input type="checkbox" ng-model="checkedStatus" ng-change="viewAccount()"> 
    Show Deactivated Account 
</div>