1

チェックボックスをオンにすると、チェックボックスがオンになっています。リクエストでチェックボックスがオンになっていると、アカウントを無効にするためにactivationstatusをfalseに送信する必要があります。私のチェックボックスは、$ 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

あなただけ$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> 

これをコントローラでどのように使用するのですか。あなたのJSONで

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

これはどのような変更をもたらすかは、とにかく同じ関数riteを参照していますか? –

+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> 
関連する問題