'How can I get form data and add it to an object in Angular?

I am using this form to take some basic information:

 <form action="/action_page.php" method="GET" name="clientForm">
        <label for="cname">Client name:</label><br>
        <input type="text" id="cname" placeholder="client name:" name="cname" required><br>
        <label for="clienturl">URL:</label><br>
        <input type="text" id="clienturl" placeholder="url:" name="clienturl" required><br><br>
        <input type="submit" value="Submit" button (click)="addClient()" >
        <input type="reset" value="Reset">
      </form>

This is the data i am currently holding:

  export const clients = [
    {
      name: 'client1',
      url: "https://www.google.com"
    },
    {
      name: 'client2',
      url: "https://www.yahoo.com"
    },
    {
      name: 'ACB',
      url: "https://www.dailymail.co.uk"
    },
    {
      name: 'client3',
      url: "https://www.youtube.com"
    },
    {

      name: 'client4',
      url: "https://www.nhs.uk"
    },
  ];

Then in my component I am struggling to get the data entered into the form and add it as an object to the existing data.



Solution 1:[1]

If you use the Reactive Forms / Angular Standard Forms in your angular app, you can get it...

<form [formGroup]="FormName" (ngSubmit)="submit()">

in TypeScript:

this.FormName.value

For more details, see the official documents

By using the traditional way, you can add in to the object

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thilrash Ameen