2016-04-29 48 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>