0

I need to add 2 empty person objects to array and after populate it. Chrome complains TypeError: object is not a function at new <anonymous>. What's wrong?

$scope.person = {
        firstName : '',
        lastName : '',
        dateOfBirth : '',
        sex : '',
        nationality : ''
    };
    $scope.persons = [];
    $scope.persons.push(new $scope.person); // error
    $scope.persons.push(new $scope.person);
J.Olufsen
  • 13,415
  • 44
  • 120
  • 185

1 Answers1

1
$scope.persons.push(angular.copy($scope.person));
$scope.persons.push(angular.copy($scope.person));

you need a copy of a person object , you cant use new keyword with it

in java, you can use class to create a object, after creating a object you can deal with it, but you cant create a new object from the object. like wise $scope.person is a object. you cant use new keyword with it.

Kalhan.Toress
  • 21,683
  • 8
  • 68
  • 92