Function to add and show up a new object in an array

I just got started with playing around with AngularJS and I would like to build an app, that just adds another person´s name and his/her date of birth. I have got already initial data (2 persons and their date of birth (dob). By writing down the full name and dob and then pressing the add button, I would like to have another person added as well as his/her dob – and this new person should be also listed and visible in the list.

So far I made it that the function creates a new object. But unfortunately I am not able to combine the input data with the new added object in a proper way. Can somebody help me? Maybe there is an easier way to do it

So far I created this:

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
    </head>
    <body>
        <script>
            var app = angular.module("myBirthApp",[]);
            app.controller("myCtrl", function($scope){
               $scope.birthdays=[
                {fullName:'Jane Doe', dateOfBirth:'08.03.1990'}, 
                {fullName:'John Doe', dateOfBirth:'19.11.1995'}];
                    // create new array with addItem!
                    $scope.addItem = function () {
                    $scope.birthdays.push($scope.addMe);
                    }
                });
                    
        </script>
        <div ng-app="myBirthApp" ng-controller="myCtrl">
            <ul>
                <li ng-repeat="x in birthdays"><p>Name: {{x.fullName}}</p> <p>Date of birth: {{x.dateOfBirth}}</p> </br></li>
            </ul>
            <form>
                <fieldset>
                    <legend>Add a person</legend>
                First name and last name: <input type="text" ng-model="fullName"></br>
                Date of birth: <input type="date" ng-model="dateOfBirth"></br>
                <button ng-click="addItem()">Add</button>
                </fieldset>
            </form>
        </div>
    </body>
</html>

Answer

You could declare a variable:

$scope.person = {
    fullName: '',
    dateOfBirth: null
};

and bind it to ngModel inputs:

<input type="text" ng-model="person.fullName"><br />
<input type="date" ng-model="person.dateOfBirth">

and then in addItem method push it to birthdays array. (Of course it needs further additions, validation checks etc but this is the basic idea)

Check here a working demo: DEMO