在AngularJS

时间:2015-06-29 14:54:01

标签: javascript angularjs prototype

我遇到了这个麻烦。

我有一个复选框,当选中复选框时我想将3个对象加载到数组中,但是当它发生时我会看到这个错误发生了六次:

错误:fnPtr不是函数 Parser.prototype.functionCall /< @ http://localhost:8383/MyApp/js/angular.js:10568:15 算[ “===”] .... 错误:fnPtr不是函数 Parser.prototype.functionCall /< @ http://localhost:8383/MyApp/js/angular.js:10568:15 算[ “>” 中] ....

我做错了什么?

这是我的代码:

HTML:

     <div class="form-group col-sm-12 subject-field">
           <label>Has children?</label>
           <input type="checkbox" ng-model="marriage.has_children" ng-change="setSons()" title="If had children check the box">
     </div>
     <div class="col-sm-12 col-md-12" ng-repeat="littleBoy in marriage.children">
     <h3>{{$index+1}}</h3>
     ...
     </div>

控制器:

     angular.module('DExpress').controller('FormController',['$scope', 
                                                    '$filter', 
                                                    '$http', '$log', 
                                                    function($scope, 
                                                             $filter, 
                                                             $http, $log)
    {

        $scope.marriage = {
               lives_togheter: false,
               has_children: false,
               celebration_date: $filter('date')(new Date(), 'dd-MM-yyyy'),
               separation_time: 0,
               another_information: "",
               state: "Montevideo",
               city: "Montevideo",
               country: "Uruguay",
               children: []
         };


         $scope.addSon = function(){
               var person = {
                             name: "",
                             surname: "",
                             birth_date: $scope.today,
                             studies: false,
                             where_studies: "School...",
                             year_of_study: "1st Grade",
                             is_disabled: false,
                             explanation: ""
               };
               $scope.marriage.children.push(person);                   
         };

        $scope.setSons = function(){
                 if($scope.marriage.has_children){
                     $scope.marriage.children=[];
                     $scope.addSon();
                     $scope.addSon();
                 }else{
                     $scope.marriage.children = [];
                 }        
        };


    }

0 个答案:

没有答案