2017-06-28 13 views
0

値を0にしたいというチェックボックスがあります。私もそれ私のコントローラ内の範囲は次のようになりますng-modelによるチェックボックスへの値の割り当て

<input type="checkbox" class="input-group inline form-control" value="0" name="" id="deletelanguage" ng-show="IsVisible" ng-model="delStat"> 

にNG-moelを割り当てました。

$scope.delStat=""; 

チェックボックスがオンの場合、チェックボックスの値を1に変更します。どうやってやるの?

+0

確認[チェックボックスのための角度DOC(https://docs.angularjs.org/api/ng/input/input%5Bcheckbox以下のように使用ng-true-value ng-false-value %5D) –

+0

['ngTrueValue'' ngFalseValue'](https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D) –

答えて

2

<input type="checkbox" class="input-group inline form-control" ng-true-value='1' id="deletelanguage" ng-show="IsVisible" ng-model="delStat"> 

var app = angular.module('plunker', []); 
 

 
app.controller('MainCtrl', function($scope) { 
 
    
 
});
<!DOCTYPE html> 
 
<html ng-app="plunker"> 
 

 
    <head> 
 
    <meta charset="utf-8" /> 
 
    <title>AngularJS Plunker</title> 
 
    <script>document.write('<base href="' + document.location + '" />');</script> 
 
    <link rel="stylesheet" href="style.css" /> 
 
    <script data-require="[email protected]" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script> 
 
    <script src="app.js"></script> 
 
    </head> 
 

 
    <body ng-controller="MainCtrl"> 
 
    <input type="checkbox" name="mycheck" ng-true-value='1' ng-false-value='0' ng-model="val">Check</input> 
 
    <br>Seleted Value :{{val}} 
 
    </body> 
 

 
</html>

関連する問題