The below code always returns false
even after I click the checkbox
. My lead advised me that the ngmodel
might not be hookedup properly with the state. I am new to angular, could someone pls help me
HTML:
<form-checkbox
required="true"
set-checkbox-touched="DeclarationRequest.declarationAgree"
servervalidate="DeclarationRequest.declarationAgree"
name="declarationAgree" id="declarationAgree" class="form-checkbox" ng-model="ctrl.checkbox.myFlag">I have read and agree to the terms above.</form-checkbox>
JS:
(function(module){
'use strict';
module.directive('Declaration', function () {
return {
templateUrl: '/client/Purchase/components/declaration/declaration.template.html',
restrict: 'E',
scope: {
declarationAgree: '='
},
bindToController: true,
controllerAs: 'control',
controller: 'DeclarationController'
};
});
function DeclarationController() {
}
module.controller('DeclarationController', DeclarationController );
DeclarationController.$inject = [];
})(angular.module('Purchase'));
You can put the ng-true-value or ng-false-value for your own false/true value , this code is from the guideline of angularjs.
<script>
angular.module('checkboxExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.checkboxModel = {
value1 : true,
value2 : 'YES'
};
}]);
</script>
<form name="myForm" ng-controller="ExampleController">
<label>Value1:
<input type="checkbox" ng-model="checkboxModel.value1">
</label><br/>
<label>Value2:
<input type="checkbox" ng-model="checkboxModel.value2"
ng-true-value="'YES'" ng-false-value="'NO'">
</label><br/>
<tt>value1 = {{checkboxModel.value1}}</tt><br/>
<tt>value2 = {{checkboxModel.value2}}</tt><br/>
</form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.