// ==========================================
// 1. MAIN COMPONENT - Add this to your existing main component
// ==========================================
// main.component.ts - ADD THESE PROPERTIES AND METHODS
export class MainComponent {
// Add this property
isModalOpen = false;
// Add this method to handle the Add button click
openCustomerModal() {
this.isModalOpen = true;
}
// Add this method to close the modal
closeModal() {
this.isModalOpen = false;
}
// Add this method to handle customer selection
onCustomerSelected(customer: any) {
console.log('Selected customer:', customer);
// Handle the selected customer here
this.closeModal();
}
}
// ==========================================
// 2. MAIN COMPONENT HTML - Add this to your template
// ==========================================
// In your main.component.html, modify your Add button:
<button class="btn btn-primary" (click)="openCustomerModal()">Add</button>
// Add this modal component tag somewhere in your main template:
<app-customer
*ngIf="isModalOpen"
(customerSelected)="onCustomerSelected($event)"
(modalClosed)="closeModal()">
</app-customer>
// ==========================================
// 3. CUSTOMER COMPONENT - Replace your existing customer component
// ==========================================
// customer.component.ts - REPLACE YOUR EXISTING CODE
import { Component, EventEmitter, Output, OnInit } from '@angular/core';
@Component({
selector: 'app-customer',
templateUrl: './customer.component.html',
styleUrls: ['./customer.component.css']
})
export class CustomerComponent implements OnInit {
@Output() customerSelected = new EventEmitter<any>();
@Output() modalClosed = new EventEmitter<void>();
customers = [
{ id: 1, name: 'Person 1' },
{ id: 2, name: 'Person 2' },
{ id: 3, name: 'Person 3' }
];
ngOnInit() {}
selectCustomer(customer: any) {
this.customerSelected.emit(customer);
}
closeModal() {
this.modalClosed.emit();
}
}
// ==========================================
// 4. CUSTOMER COMPONENT HTML - Replace your existing template
// ==========================================
// customer.component.html - REPLACE YOUR EXISTING HTML
<div class="modal-backdrop" (click)="closeModal()"></div>
<div class="modal-dialog" (click)="$event.stopPropagation()">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Clients</h4>
<button type="button" class="close" (click)="closeModal()">×</button>
</div>
<div class="modal-body">
<h4 class="modal-title" style="text-align: center;">Find client by ID</h4>
<div class="form-group">
<input type="text" class="form-control dash-form-control" placeholder="Search..." autofocus>
<div style="margin-top: 10px;">
<div class="customer-list">
<div
*ngFor="let customer of customers"
class="customer-option"
(click)="selectCustomer(customer)">
{{ customer.name }}
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" (click)="closeModal()">Cancel</button>
</div>
</div>
</div>
// ==========================================
// 5. ESSENTIAL CSS - Add this to customer.component.css
// ==========================================
.modal-backdrop {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1050;
display: flex;
align-items: center;
justify-content: center;
}
.modal-dialog {
background: white;
border-radius: 8px;
width: 90%;
max-width: 500px;
}
.modal-header {
padding: 15px 20px;
border-bottom: 1px solid #ddd;
display: flex;
justify-content: space-between;
align-items: center;
}
.close {
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
}
.modal-body {
padding: 20px;
}
.modal-footer {
padding: 15px 20px;
border-top: 1px solid #ddd;
}
.customer-option {
padding: 10px;
border: 1px solid #eee;
margin: 5px 0;
cursor: pointer;
border-radius: 4px;
}
.customer-option:hover {
background-color: #f8f9fa;
}
Try adding the isModalOpen property also add the three methods, Modify the add button to call (click)="openCustomerModal()" also Add the <app-customer> tag with the event bindings
Later try updating your Customer Component by replacing your existing TypeScript code with the version that includes @Output() events
Replace your HTML template with the new version that includes click handlers
Thus add the CSS and Make sure FormsModule is imported