im currently working on a small task which is essentially a customer form where users can submit data and the data is then stored in an array and presented as a list.
I have managed to complete the form and i can submit data into an array and output it into a list. i am know trying to figure out how i can then click on the data in the list and have the data re-populate the fields in the form and for me then to edit or delete.
i have searched online for "clickable lists" and "actionable lists" but there doesnt seem to be anything i can use as it is all static. i have seen someone use a button in the list but that also doesnt work as all my data is then added to one big button. i have come across material UI but i would prefer to do it without using a library.
i have attached my code below:
contacts.component.html:
<!-- <p>contacts works!</p> -->
<div class="main">
<!-- <input type="text" class="inputSearch" placeholder="search"> -->
<label for="name" class="nameLbl">Name</label>
<ul>
<li *ngFor="let contact of contacts">{{contact.firstName}}</li>
</ul>
</div>
<form #add="ngForm" (ngSubmit)="addContact(add) ; add.resetForm()">
<div class="form-group">
<label for="text">First Name</label>
<input class="inpt" type="text" id="text" name="firstName" ngModel />
</div>
<div class="form-group">
<label for="text">Last Name</label>
<input class="inpt" type="text" id="text" name="lastName" ngModel />
</div>
<div class="form-group">
<label for="text">Email</label>
<input class="inpt" type="email" id="text" name="email" ngModel />
</div>
<div class="form-group">
<label for="text">Address 1</label>
<input class="inpt" type="text" id="text" name="address1" ngModel />
</div>
<div class="form-group">
<label for="text">Address 2</label>
<input class="inpt" type="text" id="text" name="address2" ngModel />
</div>
<div class="form-group">
<label for="text">City</label>
<input class="inpt" type="text" id="text" name="city" ngModel />
</div>
<div class="form-group">
<label for="text">PostCode</label>
<input class="inpt" type="text" id="text" name="postcode" ngModel />
</div>
<div class="form-group">
<label for="text">Telephone</label>
<input class="inpt" type="number" id="text" name="telephone" ngModel />
</div>
<br>
<button class="addContactBtn">Add Contact</button>
</form>
</div>```
contacts.component.ts:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-contacts',
templateUrl: './contacts.component.html',
styleUrls: ['./contacts.component.css']
})
export class ContactsComponent {
contacts: any = []
addContact(add: any) {
console.log("Contact Added", add);
this.contacts.push(add.value)
console.log(this.contacts);
}
}