2016-04-29 57 views
0

即使在单击checkbox后,下面的代码始终为returns false。我的领导告诉我,ngmodel可能没有适当的与国家挂钩。我是新来的角度,可能有人请帮助我angular - 即使复选框已选中,此声明字段始终为假

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')); 
+0

你可以把你的$ scope对象放在问题中吗? – Jai

+0

@Jai:更新了队友,但我认为在这里提供解决方案或解决方案并不相关。但是,你走了,看看,让我知道什么是错的? – Learner

+0

你的代码“总是返回false”...从哪里? – iulian

回答

-1

你可以把为NG-真值或NG-假值的自己的假/真值,这个代码是从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>