lundi 1 mai 2017

Implementation of checkbox in angularjs

I like to use checkbox in AngularJs for user's decision. I can't catch checkbox's state change in my AngularJs code.

My html code is

<div ng-show="acceptrequest">
     <label class="switchnmn">
        <input type="checkbox" ng-change="stateChanged()" checked>
        <div class="slidernmn round"></div>
    </label>
    <b style="font-size:15px">I am able to accept customer's any request date.</b>
</div>

AngularJs code is

    $scope.stateChanged = function (    ) {
        if(){ //If it is checked
          $scope.acceptrequest = true;
       }
       else
          $scope.acceptrequest = false;
    }

When checkbox is checked, $scope.acceptrequest should be true and unchecked $scope.acceptrequest should be false. How can I do that?

I implemented checkbox is slider in css

.switchnmn {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switchnmn input {display:none;}

.slidernmn {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slidernmn:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slidernmn {
  background-color: #2196F3;
}

input:focus + .slidernmn {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slidernmn:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

/* Rounded sliders */
.slidernmn.round {
  border-radius: 34px;
}

.slidernmn.round:before {
  border-radius: 50%;
}

label, b {
  vertical-align: middle;
}




Aucun commentaire:

Enregistrer un commentaire