angular-js中checbox的未定义值

时间:2017-09-25 11:00:19

标签: html angularjs

HTML部分:

<label>Do you want to check this?  <input type="checkbox" ng-model="checkModel" >
      </label><br/>

控制器部分:

  $http.post("InsertParticipant.jsp?comments1=" + $scope.comment +  "&checked_value=" + $scope.checkModel + "&request_id=" +id).
                                         then(function(response){
                                                           if(response.data.match("SUCCESS")){

                                        alert("Entry has been added");

                                }
                                else{
                                        alert("Sorry something went wrong Try filling it again");

                                }

复选框值未定义。有人可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

您应该将添加到输入中。

在AngularJS中,您可以设置:

  • ngTrueValue - 选中时应设置表达式的值。
  • ngFalseValue - 未选中时应将表达式设置的值。

Check input[checkbox] documentation.

答案 1 :(得分:0)

您需要为checkModel变量添加值,如此

$scope.checkModel = { value1 : true, value2 : 'YES' };

请参阅angular.js decumentation以及示例:angular-input[checkbox]